c# - 我如何在 GDI+ 中将一个位图图像叠加到另一个位图图像上?

标签 c# gdi+ heatmap

我使用 GDI+ 制作了热图 bmp,我想将它叠加在我的 bmp map 上。我已经将这两个 bmp 保存到磁盘,它们看起来不错,我只需要一种方法将它们放在一起。有什么办法可以做到这一点,也许使用 Graphics 对象?透明度/阿尔帕是如何参与的?

我是 GDI 编程的新手,所以请尽可能具体。


好的 - 这是一个答案。在某些时候,我需要了解 GDI+ 的工作原理...

我无法解决透明度问题,但这行得通。它只是将非白色像素从叠加层复制到 map :

        for (int x = 0; x < map.Width; x++)
            for (int y = 0; y < map.Height; y++) {
                Color c = overlay.GetPixel(x, y);
                if ((c.A != 255) || (c.B != 255) || (c.G != 255) || (c.R != 255))
                    map.SetPixel(x, y, c);     

最佳答案

这应该可以完成工作...

此时,您要叠加到主图像上的图像将位于主图像的左上角,因此 new Point(0,0)。但是,您可以更改此设置以将图像定位到您想要的任何位置。

void SuperimposeImage()
        {
            //load both images
            Image mainImage = Bitmap.FromFile("PathOfImageGoesHere");
            Image imposeImage = Bitmap.FromFile("PathOfImageGoesHere");

            //create graphics from main image
            using (Graphics g = Graphics.FromImage(mainImage))
            {
                //draw other image on top of main Image
                g.DrawImage(imposeImage, new Point(0, 0));

                //save new image
                mainImage.Save("OutputFileName");
            }


        }

关于c# - 我如何在 GDI+ 中将一个位图图像叠加到另一个位图图像上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2966316/

相关文章:

javascript - 如何销毁 heatmap.js 实例?

c# - 在托管代码和非托管代码之间共享 Graphics 对象时丢失抗锯齿

python - 如何在python中为热图的特定元素添加颜色边框或类似的突出显示?

r - 以图像为背景的热图

c# - 使用 ExecuteNonQuery() 时无法检测到 SQL 错误

windows - GDIPlus Windows 用户界面的 future : which will be the replacement?

c# - 模拟时钟 - 在标签上绘制时钟臂

c# - 包含自己模型类型列表的模型(递归建模?)

c# - 如何使用泛型类型的子类初始化泛型属性?

c# - .Net/C# - 使用 GAC 的优缺点