C# 如何重叠图像?

发布于 2024-11-01 18:51:35 字数 349 浏览 3 评论 0原文

可能的重复:
如何将两个图像合并为单个 Jpeg < /p>

我有 2 个图像,

Image.FromFile("images/1.png");
Image.FromFile("images/2.png");

我想重叠这些图像并构建一个新图像,我该怎么做?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寒江雪… 2024-11-08 18:51:35
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);
}

如果您不想缩放或平移任何图像,这是最简单的方法。结果将存储在 image1 中。您还可以创建一个新图像来执行此操作、偏移图像、缩放图像、更改透明度等。

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..

贪恋 2024-11-08 18:51:35

好吧,这取决于您正在寻找什么类型的效果,但您没有给我们太多信息,因此您可以从简单的附加例程开始。循环遍历两个图像的共享区域中的每个像素,并将像素分量值加在一起,限制在最大值以避免溢出(假设每个分量只有一个字节,则可能为 255)。

您可以使用 GDI+ 位图方法 GetPixelSetPixel 来执行此操作,或者如果事实证明这太慢,您可以调用 LockBits 并直接获取内存中的图像数据。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文