- About Graphics Mill
- What's New?
- Breaking Changes in Graphics Mill 12
- Breaking Changes in Graphics Mill 11
- Features
- Supported File Formats
- System Requirements
- Getting Started
- Your First Application with Graphics Mill
- Understanding Image Processing Approaches in Graphics Mill
- Evaluating Graphics Mill
- Registering Production License Keys
- Upgrading from Graphics Mill 5
- Installation and Redistribution Notices
- Graphics Mill Configuration
- Using Graphics Mill with Microsoft Azure
- Using Graphics Mill in .NET projects
- Working with Image Formats
- Transforming Images (Resize, Rotate, Crop)
- Working with Metadata
- Color Management and Color Reduction
- Drawing Text and Graphics
- Color Keying (Green Screen Removal)
- Channels and Pixel Data
- Color and Tone Correction
- Working with Photoshop (PSD) Files
- Image Filters
- Processing Large Images
- Basics of Image Processing
- Troubleshooting
- Class Library Reference
- Licensing
- End User License Agreement
- Copyright Notices
Your First Application with Graphics Mill
This topic describes how to get started with Graphics Mill and shows how to write a simple image processing routine. The routine loads an image, resizes it, and draws a watermark on it.
Image Processing
To process relatively small images, you can use bitmaps. Graphics Mill can load bitmaps from various image formats, save them to these formats, apply different transformations on bitmaps, and draw text, graphic primitives, or other images on them. You can draw on bitmaps with any pixel format supported by Graphics Mill , except for indexed formats. Even extended formats (16 bits per channel), CMYK, and formats with alpha channels are handled correctly.
First, you can add the following namespaces to our application to make the code more attractive.
using Aurigma.GraphicsMill;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
using Aurigma.GraphicsMill.Drawing;
The following imaging algorithm comprises three main operations with a bitmap: load the bitmap from a file, resize it, and then draw watermark text on it. Here is the complete code implementing this algorithm:
private static Bitmap ResizeAndWatermark(string sourceImagePath, int size, string text)
{
// Load an image from the specified file.
var bitmap = new Bitmap(sourceImagePath);
// Resize the image to the specified size.
bitmap.Transforms.Resize(size, size, ResizeInterpolationMode.High, ResizeMode.Fit);
// Draw watermark text.
using (var graphics = bitmap.GetGraphics())
{
var textToDraw = new PlainText(text, graphics.CreateFont("Calibri", bitmap.Height / 20),
new SolidBrush(RgbColor.White), graphics.Width - 1, graphics.Height - 1,
TextAlignment.Right);
graphics.DrawText(textToDraw);
}
return bitmap;
}
All drawing operations are built around the Graphics abstraction. The bitmap itself is storage for pixels and does not support any drawing operations. That is why we use Graphics to draw on the bitmap. If you want to learn how to draw on bitmaps in detail, read the Drawing section.
Adding Graphics Mill to Your Project
The easiest way to add Graphics Mill to your project is NuGet. Run the following command in the project folder:
dotnet add package Aurigma.GraphicsMill.Core.x64
Use Aurigma.GraphicsMill.Core.x86 if your application targets the x86 platform.
If you prefer not to use NuGet, install Graphics Mill SDK and add a reference to the Aurigma.GraphicsMill.dll assembly.
You can find it in
C:\Program Files (x86)\Aurigma\Graphics Mill 12 SDK\Binaries\net472\xNN\ for .NET Framework 4.7.2 and higher,
or in
C:\Program Files (x86)\Aurigma\Graphics Mill 12 SDK\Binaries\net9.0\xNN\ for .NET 9 and higher.
NN is 64 or 86.
For more information, read Installation and Redistribution Notices.