Graphics Mill for .NET provides rich image blending features. It allows overlaying one image over another one. You can set different combine modes, coordinates of the source image, the rectangle at the destination bitmap to fit the image in, and even a portion of source image to get. Also you can specify overall opacity of the source image.
There are two equivalent ways to draw the bitmap with Graphics Mill for .NET:
The code example below demonstrates the how to blend two bitmaps with alpha blending combine mode.
Fig. 1. Alpha blending combine mode example
'Load background image Dim bitmap As New Aurigma.GraphicsMill.Bitmap("C:\pyramid.jpg") 'Load small image (foreground image) Dim smallBitmap As New Aurigma.GraphicsMill.Bitmap("C:\watermark.png") 'Draw foreground image on background with transparency smallBitmap.Draw(bitmap, 10, bitmap.Height - smallBitmap.Height - 10, _ smallBitmap.Width, smallBitmap.Height, _ Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 0.7F, _ Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality)
//Load background image Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"C:\pyramid.jpg"); //Load small image (foreground image) Aurigma.GraphicsMill.Bitmap smallBitmap = new Aurigma.GraphicsMill.Bitmap(@"C:\watermark.png"); //Draw foreground image on background with transparency smallBitmap.Draw(bitmap, 10, bitmap.Height-smallBitmap.Height-10, smallBitmap.Width, smallBitmap.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 0.7f, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);
The arguments of the Draw method above mean the following:
There is also another way to combine images—using a masked transform. A masked transform is a transform that allows applying effects to a region defined by a mask. Such transforms inherit from the MaskedBitmapTransform. The mask that sets the areas where the changes will be made is a grayscale bitmap, where the black areas will be transparent, and the white ones will be opaque.
The Combiner transform belongs to to such transforms. It lets you combine several images on the same background using a mask. Look at the following picture:
Fig. 2. Masked transform example
In this picture, two photographs are positioned at the specified placeholders over a background. To do that you will need to carry out these steps:
To make the above instructions clearer, look at the following diagram and at the code example below.
Fig. 3. Masked transform exploded diagram
'Photos for the collage. Dim photo1 As New Aurigma.GraphicsMill.Bitmap("D:\photo1.jpg") Dim photo2 As New Aurigma.GraphicsMill.Bitmap("D:\photo2.jpg") 'Background image. Dim background As New Aurigma.GraphicsMill.Bitmap("D:\background.jpg") 'Mask. Dim mask As New Aurigma.GraphicsMill.Bitmap("D:\mask.jpg") 'Coordinates of placeholders. Dim point1 As New Point(160, 160) Dim point2 As New Point(550, 420) 'Create the transform. Dim combiner As New Aurigma.GraphicsMill.Transforms.Combiner combiner.CombineMode = Aurigma.GraphicsMill.Transforms.CombineMode.Copy 'Combine with the first image. combiner.SourceBitmap = photo1 combiner.SourceRectangle = New RectangleF(0, 0, photo1.Width, photo1.Height) combiner.DestinationRectangle = New RectangleF(point1.X - photo1.Width / 2, _ point1.Y - photo1.Height / 2, photo1.Width, photo1.Height) combiner.ApplyMaskTransform(background, mask) 'Combine with the second image. combiner.SourceBitmap = photo2 combiner.SourceRectangle = New System.Drawing.RectangleF(0, 0, photo2.Width, _ photo2.Height) combiner.DestinationRectangle = New System.Drawing.RectangleF(point2.X - _ photo2.Width / 2, point2.Y - photo2.Height / 2, photo2.Width, _ photo2.Height) combiner.ApplyMaskTransform(background, mask) background.Save("D:\collage.jpg")
//Photos for the collage. Aurigma.GraphicsMill.Bitmap photo1 = new Aurigma.GraphicsMill.Bitmap(@"D:\photo1.jpg"); Aurigma.GraphicsMill.Bitmap photo2 = new Aurigma.GraphicsMill.Bitmap(@"D:\photo2.jpg"); //Background image. Aurigma.GraphicsMill.Bitmap background = new Aurigma.GraphicsMill.Bitmap(@"D:\background.jpg"); //Mask. Aurigma.GraphicsMill.Bitmap mask = new Aurigma.GraphicsMill.Bitmap(@"D:\mask.jpg"); //Coordinates of placeholders. Point point1 = new Point(160, 160); Point point2 = new Point(550, 420); //Create the transform. Aurigma.GraphicsMill.Transforms.Combiner combiner = new Aurigma.GraphicsMill.Transforms.Combiner(); combiner.CombineMode = Aurigma.GraphicsMill.Transforms.CombineMode.Copy; //Combine with the first image. combiner.SourceBitmap = photo1; combiner.SourceRectangle = new RectangleF(0, 0, photo1.Width, photo1.Height); combiner.DestinationRectangle = new RectangleF(point1.X - photo1.Width / 2, point1.Y - photo1.Height / 2, photo1.Width, photo1.Height); combiner.ApplyMaskTransform(background, mask); //Combine with the second image. combiner.SourceBitmap = photo2; combiner.SourceRectangle = new System.Drawing.RectangleF(0, 0, photo2.Width, photo2.Height); combiner.DestinationRectangle = new System.Drawing.RectangleF(point2.X - photo2.Width / 2, point2.Y - photo2.Height / 2, photo2.Width, photo2.Height); combiner.ApplyMaskTransform(background, mask); background.Save(@"D:\collage.jpg");