c#:如何使位图透明

Yoo*_*oon 1 c# graphics bitmap transparent

Bitmap tmp = new Bitmap(1000, 1000);
Graphics g = Graphics.FromImage(tmp);

Image img = Bitmap.FromFile(LoadPath);
Image img2 = Bitmap.FromFile(TempPath);

g.DrawImage(img, 0, 0);
g.DrawImage(img2, 250, 250);
Run Code Online (Sandbox Code Playgroud)

'img' 和 'img2' 是带有透明部分的图像。当我运行代码时,透明部分显示为黑色。这是为什么?

在此处输入图片说明

EAK*_*EAM 5

看看这里

private void MakeTransparent_Example1(PaintEventArgs e)
{

// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Grapes.gif");

// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
    myBitmap.Height);

// Make the default transparent color transparent for myBitmap.
myBitmap.MakeTransparent();

// Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
    myBitmap.Width, myBitmap.Height);
}
Run Code Online (Sandbox Code Playgroud)