arklumpus/VectSharp

Can I use the repo to merge 2 PNG files?

Closed this issue · 4 comments

Hello:
I have 2 same size PNG files: 1.PNG and 2.PNG, they both have the size of 1280px by 720px.
I want to merge them: 1.PNG on top of 2.PNG (I will use 2.PNG as background). The merge is like in Photoshop flatten different layers into one final image.
Please advise,
Thanks,
1

Hi,
I forgot the second image, here it comes!
2

Hi,
I would like the following result in the image:
3

Sorry for the delay.

Sure, it shouldn't be too hard! Make sure you are referencing VectSharp.MuPDFUtils and VectSharp.Raster, then you can do something like:

using VectSharp;
using VectSharp.MuPDFUtils;
using VectSharp.Raster;

// ...

// Create the page for the complete image
Page pag = new Page(1280, 720);

// Load the background and foreground image (the RasterImageFile class comes from VectSharp.MuPDFUtils)
using RasterImageFile foreground = new RasterImageFile("1.png");
using RasterImageFile background = new RasterImageFile("2.png");

// Draw the two images
pag.Graphics.DrawRasterImage(0, 0, 1280, 720, background);
pag.Graphics.DrawRasterImage(0, 0, 1280, 720, foreground);

// Save the output as a PNG file
pag.SaveAsPNG("3.png");

OK, thanks!