C# How do I overlap Images? [duplicate]
Possible Duplicate:
How to merge two images into a single Jpeg
I have 2 images,
Image.FromFile("images/1.png");
Image.FromFile("images/2.png");
i want to overlap these images and construct a new image how do i do it?
Thanks
Image image1 = Image.FromFile("images/1.png");
Image image2 = Image.FromFile("images/2.png");
using(Graphics g = Graphics.FromImage(image1)) {
g.DrawImageUnscaled(image2, 0, 0);
}
Is the simplest way, if you don't want to scale or translate either image. The result will be stored in image1. You can also create a new image to do this, offset the images, scale them, change transparency, etc..
Well, it depends on what type of effect you are looking for, but you haven't given us much info, so you could start with a simple additive routine. Loop through each pixel in the shared area of the two images and add the pixel component values together, clamping at the maximum to avoid overflow (probably 255 assuming a single byte per component).
You can use the GDI+ bitmap methods GetPixel
and SetPixel
to do this, or if that proves too slow you can call LockBits
and get directly at the image data in memory.
精彩评论