We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to overlay 4 images with mixed and transparence?

Hi, Support:

Would you tell me how to reach this purpose?
That is to say:
There have 4 images, whose filename may be Back.png, 1st.png,2nd.png,3th.png, I want to overlay 1st.png on the Back.png with 0.5 transparence, then overlay 2nd.png over 1st.png with 0.3 transparence, then overlay 3th.png with 0.2 transparence, finally save back.png.
Is there any method to reach it on Vb.net?
For example:
Aspose.Imaging.Image.Overlayers Back.png,1st.png,x,y,w,h,Opacity1
Aspose.Imaging.Image.Overlayers Back.png,2nd.png,x,y,w,h,Opacity2
Aspose.Imaging.Image.Overlayers Back.png,3th.png,x,y,w,h,Opacity3

Besides, Is there any method to print text on the image, for example:
Aspose.Imaging.Image.AddText Back.png,Text,x,y,Fontname,Fontsize,FontStyle,Fontcolor,FontShape

Thanks for your help.

@ducaisoft, Aspose.Imaging does not have built-in public API function for overlay. You can try 2 ways:

  1. Prepare manually with code images with specified transparency and than use Graphics.DrawImage(). Also you can use Graphics to draw text as you asked - Graphics.DrawString() method. Here is sample code that can draw on background image another png image with opacity 0.3
using (PngImage image = (PngImage)Image.Load(@"e:\Aspose.Imaging.TortoiseGitVersion\aspose.imaging.net\test\testdata\Images\Png\tiger0.png"))
                using (PngImage image2 = (PngImage)Image.Load(@"e:\Aspose.Imaging.TortoiseGitVersion\aspose.imaging.net\test\testdata\Images\Png\input.png"))
                    PngOptions options = new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha };
                    options.Source = new FileCreateSource(@"c:\Users\USER\Downloads\result.png", false);
                    using (PngImage image3 = (PngImage)Image.Create(options,image2.Width,image2.Height))
                        image3.SaveArgb32Pixels(image2.Bounds, image2.LoadArgb32Pixels(image2.Bounds));
                        Color[] colors = image3.LoadPixels(image3.Bounds);
                        double opacity = 0.3; //30% opacity
                        for (int i = 0; i < colors.Length; i++)
                            colors[i] = Color.FromArgb((byte)(opacity * colors[i].A), colors[i].R, colors[i].G, colors[i].B);
                        image3.SavePixels(image3.Bounds, colors);
                        Graphics gr = new Graphics(image);
                        gr.DrawImage(image3, 100, 100);
  1. You can implement your own blending function that will process your 2 images and blend colors over them as BLEND(back, front, alpha) ((front * alpha) + (back * (255 - alpha))) / 255
R = BLEND(backR, frontR, frontAlpha);
G = BLEND(backG, frontG, frontAlpha);
B = BLEND(backB, frontB, frontAlpha);

Based on your case we will investigate is there any possibility to imploy application of blending for images to public API or adding new filter alpha(opacity) as exists in css.