如何在另一个GDI +叠加一个位图图像? [英] How do I superimpose one bitmap image on another in GDI+?

查看:360
本文介绍了如何在另一个GDI +叠加一个位图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用GDI +我做了一个热图BMP和我想塞给它在我的BMP图的顶部。我已经保存两个BMP的磁盘,它们看起来不错,我只是需要一种方法来把它们放在一起。有没有办法做到这一点,可能使用的Graphics对象?透明/ ALPA如何参与?



我很新的GDI编程,所以请尽可能详细。






确定 - 这里有一个答案。在某些时候,我需要学习GDI +是如何工作的?



我不能让周围的transarency的问题,但这个工程。它只是从叠加到地图副本非白色像素:

 的for(int x = 0; X<地图.WIDTH; X ++)
为(INT Y = 0; Y< map.Height; Y ++){
颜色C = overlay.GetPixel(X,Y);
如果((CA!= 255)||(CB!= 255)||(CG!= 255)||(CR!= 255))
map.SetPixel(X,Y,C );


解决方案

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



目前要叠加到主图像将设在主图像的左上角的形象,因此新点(0 ,0)。但是你可以改变这个给你想要的任何地方找到该图像。

 无效SuperimposeImage()
{
//加载两个图像
图像mainImage = Bitmap.FromFile(PathOfImageGoesHere);
图像imposeImage = Bitmap.FromFile(PathOfImageGoesHere);

//创建一个使用(图形G = Graphics.FromImage(mainImage))
{
//在主图像的顶部绘制其他图像来自主图像
显卡
g.DrawImage(imposeImage,新点(0,0));

//保存新的映像
mainImage.Save(OutputFileName);
}


}


Using GDI+ I've made a heatmap bmp and I'd like to superimpose it on top of my bmp map. I've saved the two bmps to disk, and they look good, I just need a way to put them together. Is there any way to do this, perhaps using the Graphics object? How is transparency/alpa involved?

I'm very new to GDI programming so please be as specific as possible.


OK - here's an answer. At some point I need to learn how GDI+ works...

I couldn't get around the transarency issues, but this works. It just copies the non-white pixels from the overlay to the 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);     

解决方案

This should do the job...

At the moment the Image you want to superimpose onto the main image will be located in the top left corner of the main Image, hence the new Point(0,0). However you could change this to locate the image anywhere you want.

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");
            }


        }

这篇关于如何在另一个GDI +叠加一个位图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆