4

GDI+ を使用してヒートマップ bmp を作成しました。それを bmp マップの上に重ねたいと思います。2 つの bmp をディスクに保存しましたが、見栄えは良いです。それらをまとめる方法が必要なだけです。おそらく Graphics オブジェクトを使用して、これを行う方法はありますか? 透明性/アルファはどのように関係していますか?

私はGDIプログラミングに非常に慣れていないので、できるだけ具体的に教えてください。


OK - これが答えです。ある時点で、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

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


        }
于 2010-06-03T13:36:15.523 に答える