This application is useful to generate thumbnails from images in a few minutes with some interesting effects and features.
You can also insert text over images in semitransparence, defining its position, size, shadow, and optionally with a background shape like a rectangle or an ellipse and a 3D effect. Moreover you can impress a watermark image on the target image defining the transparency key, the size in percent respect of the target image, the transparency level, and the position. You can convert images between formats. Finally, you can make an interesting shadow effect like a picture over a sheet. All the elaborations could be done in batch.
Several formats are supported: JPG (with customizable compression level), GIF, PNG, WMF, TIFF, EXIT and ICO.
The tool has a nice look and a user friendly interface.
There are a lot of applications or code samples that make a resize of an image with GDI+.
The basic idea for resizing pictures is well explained in the article Resizing a Photographic image with GDI+ for .NET.
The basic idea for the watermark is well explained in the article Creating a Watermarked Photograph with GDI+ for.NET.
The implementation for resizing and impressing watermark is not much different from the quoted articles, but with some small differences.
The user can navigate files and folders for choosing desired images using the look appeal treeview on the right side of the application window. With a simple double click on a file, an image can be added to panel, otherwise with a left click a context menu appears and makes possible to the user to add or remove a single image or an entire directory containing several images. The presence of the same image on the work panel is checked. When a file or a directory is selected on the treeview, its properties like size, name, etc. are shown on the property grid. If the selected file is an image, a preview is visible just below the navigation tree.
Using the Code
The project is composed of several classes. The most important ones are:
UImageContainer - Contains the
workpanel and the preview for files and images
UDirTree - Provides the folder and files navigation
Panello - Is the
workpanel that contains several
Uimage - The user control that displays an image on the work panel
CImage - Provides the main image processing like resize, watermark, shadow effect, JPG saving, etc.
The follow code lines create the shadow effect:
public void makeshadow(ref Bitmap img, Color backcolor)
int imgWidth = img.Width;
int imgHeight = img.Height;
Bitmap workingimg = new Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb);
Graphics imgGraphic = Graphics.FromImage(workingimg);
int width = (int)((float)img.Width * 94 / 100);
int height = (int)((float)img.Height * 94 / 100);
SolidBrush BrushShadow = new SolidBrush(Color.FromArgb(10, 0, 0, 0));
float steps = ((float)imgWidth - width) / 20;
float sottr = 0f; for (float i = 0; i < 10; i++)
imgGraphic.FillRectangle(BrushShadow, new Rectangle((int)(sottr),
(int)sottr, (int)((float)width+sottr), (int)((float)height+sottr)));
sottr += steps;
imgGraphic.DrawImage(img, new Rectangle(0, 0, width, height), 0, 0,
imgWidth, imgHeight, GraphicsUnit.Pixel);
img = workingimg;
Points of Interest
To enhance the speed of the images elaboration, I made the user free to choose the number of threads that will compute the work from 1 to 10 from a numericalupdown control in the settings panel. The set of images are subdivided into intervals based on the number of maximum usable threads.
The work can be suspended, resumed and aborted by the user.
for (int i = 0 ; i < 11; i++)
threads[i] = new Thread(StarkWork);
threads[i].Priority = ThreadPriority.Lowest;
threads[i].IsBackground = false;
intSimultaneous = CONCURRENT_THREADS;
int interval = (int)Math.Floor((double)((double)total / (double)Simultaneous));
int accumulator = 0;
for (int i = 0; i < Simultaneous-1; i++)
ThreadInterval Bounds = new ThreadInterval();
Bounds.LowerBound = accumulator;
Bounds.UpperBound = accumulator+interval;
accumulator += interval;
ThreadInterval BoundsRemained = new ThreadInterval();
BoundsRemained.LowerBound = accumulator;
BoundsRemained.UpperBound = total;
Some Cool Features
The user can choose the transparency key color simply by clicking on the watermark image.
With this tool, you can make thumbnails like this:
Future Developments and Updates
I plan to modify this tool for creating HTML pages.
I have made the modification in another article: An Application to Create Interesting and Fully Customizable Web Photo Gallery.
I chose to keep this article unchanged and attached the code because the target is different: this article is about thumbnails generator in batch, the new article ("Extended Web Gallery") is about HTML pages generation (with plugins).
For more information like user documentation, visit this page.
English is not my first language, so please excuse any mistakes. This is my first article for The Code Project, so any suggestions and/or feedback will be appreciated.