Creating thumbnails is an important task in file browser applications and other similar software. Using Graphics Mill you can not only create thumbnails, but also make them look unusual and attractive. This article describes how to add the following artistic effects to thumbnails:
This topic aims to give you some ideas about how you can beautify thumbnails. Of course, you can change and combine the described methods or create your own.
This article examines applying effects to thumbnails. For basic information on how to create thumbnails see the EXIF and IPTC Metadata and Resizing and Cropping Images topics.
The following figure illustrates the feathered edge border. This effect can be performed by using the Spray transform:
The following code gets the thumbnail from an image's EXIF metadata, applies the Spray transform on it, and saves the result:
using (var jpegReader = new JpegReader(@"Images\in.jpg")) { using (var thumbnail = (Bitmap) (jpegReader.Exif[ExifDictionary.Thumbnail])) { //Apply Spray transform thumbnail.Transforms.Spray(20, 12, FadeType.Linear, 0, RgbColor.White); //Save the result thumbnail.Save(@"Images\out.jpg"); } }
The other easy way to decorate thumbnails is adding a shadow, like this one:
The following code gets the thumbnail from an image's EXIF metadata, applies the Shadow transform on it, and saves the result:
using (var jpegReader = new JpegReader(@"Images\in.jpg")) { using (var thumbnail = (Bitmap)(jpegReader.Exif[ExifDictionary.Thumbnail])) { //Add the alpha channel if (!thumbnail.HasAlpha) thumbnail.Channels.SetAlpha(1); //Apply Shadow transform thumbnail.Transforms.Shadow(RgbColor.Black, 4, 4, 10, true); //Flatten alpha channel thumbnail.Channels.RemoveAlpha(RgbColor.White); thumbnail.Save(@"Images\out.jpg"); } }
A totally different approach to decorating images is drawing on them. The AdvancedDrawing.Graphics class allows the drawing of lines, curves, shapes, and text on images. The following figure demonstrates the advanced border containing corner boxes and text:
For more information about drawing in Graphics Mill see the Drawing Text and Graphics section.
The following code gets the thumbnail from an image's EXIF metadata, draws the advanced border illustrated above on the thumbnail, and saves the result:
using (var jpegReader = new JpegReader(@"Images\in.jpg")) { using (var thumbnail = (Bitmap)(jpegReader.Exif[ExifDictionary.Thumbnail])) { //Size of corner box int boxSize = 5; //Margin of corner box int boxMargin = 1; //Height of bottom panel int bottomHeight = 14; using (var graphics = thumbnail.GetAdvancedGraphics()) { //Draw bottom panel graphics.FillRectangle(new SolidBrush(new RgbColor(208, 208, 255, 128)), 0, thumbnail.Height - bottomHeight, thumbnail.Width, bottomHeight); var pen = new Pen(new RgbColor(208, 208, 255, 80), 1); for (int i = thumbnail.Height - bottomHeight + 2; i <= thumbnail.Height; i += 5) { graphics.DrawLine(pen, 0, i, thumbnail.Width - 1, i); } //Draw text var text = new PlainText("Watermark", graphics.CreateFont("Verdana", "bold", 10), new SolidBrush(new RgbColor(0, 0, 128, 192)), new System.Drawing.PointF(thumbnail.Width / 2 + 1, thumbnail.Height - bottomHeight), TextAlignment.Center); graphics.DrawText(text); //Draw white boxes in the corners of picture var brush = new SolidBrush(RgbColor.White); graphics.FillRectangle(brush, 0, 0, boxSize - 1, boxSize - 1); graphics.FillRectangle(brush, thumbnail.Width - boxSize + 1, 0, boxSize - 1, boxSize - 1); graphics.FillRectangle(brush, 0, thumbnail.Height - boxSize + 1, boxSize - 1, boxSize - 1); graphics.FillRectangle(brush, thumbnail.Width - boxSize + 1, thumbnail.Height - boxSize + 1, boxSize - 1, boxSize - 1); //Draw points in the center of corners box brush = new SolidBrush(new RgbColor(160, 160, 255, 255)); graphics.FillRectangle(brush, boxMargin, boxMargin, boxSize - 2 * boxMargin - 1, boxSize - 2 * boxMargin - 1); graphics.FillRectangle(brush, thumbnail.Width - boxSize + 1 + boxMargin, boxMargin, boxSize - 2 * boxMargin - 1, boxSize - 2 * boxMargin - 1); graphics.FillRectangle(brush, boxMargin, thumbnail.Height - boxSize + 1 + boxMargin, boxSize - 2 * boxMargin - 1, boxSize - 2 * boxMargin - 1); graphics.FillRectangle(brush, thumbnail.Width - boxSize + 1 + boxMargin, thumbnail.Height - boxSize + 1 + boxMargin, boxSize - 2 * boxMargin - 1, boxSize - 2 * boxMargin - 1); thumbnail.Save(@"Images\out.jpg"); } } }