开发者

C# How do I overlap Images? [duplicate]

This question already has answers here: 开发者_JS百科 Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜