4

使用 GDI+,我制作了一个热图 bmp,我想将它叠加在我的 bmp 地图之上。我已将两个 bmp 保存到磁盘,它们看起来不错,我只需要一种方法将它们放在一起。有没有办法做到这一点,也许使用 Graphics 对象?透明度/ alpa 是如何涉及的?

我对 GDI 编程非常陌生,所以请尽可能具体。


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

我无法解决透明度问题,但这有效。它只是将非白色像素从叠加层复制到地图:

        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);     
4

1 回答 1

7

这应该做的工作......

目前,您要叠加到主图像上的图像将位于主图像的左上角,因此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");
            }


        }
于 2010-06-03T13:36:15.523 回答