c#:如何使位图透明
c# : How to make a 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);
'img'和'img2'是有透明部分的图像。
当我 运行 代码时,透明部分显示为黑色。
这是为什么?
看这里
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);
}
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);
'img'和'img2'是有透明部分的图像。 当我 运行 代码时,透明部分显示为黑色。 这是为什么?
看这里
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);
}