我有一个 JPG 图像,并将它放在一个表格的图片框中,但是,它看起来像这样:
我怎样才能使图片的白色部分消失,只出现彩色部分?
您可以在 Bitmap 类上使用MakeTransparent方法。所以它会像
Bitmap b = new Bitmap("img.jpg")
b.MakeTransparent(Color.White);
pictureBox.Image = b;
但我建议您使用 PNG 而不是 JPG,原因是:a)更好的质量(对于像这样的图像)c)像这样的图像更小的尺寸 b)对透明背景的原生支持。
看看它们之间有什么区别http://www.bing.com/search?setmkt=en-US&q=PNG+vs+JPG
尝试
Bitmap bmp = (Bitmap)Image.FromFile( @"C:\your_k.bmp" ); //Load a bitmap from file
bmp.MakeTransparent(Color.White) //Do the work!
//if you have a varient color combination you can use RGB Combination as follows
//bmp.MakeTransparent( Color.FromArgb( 255, 255 255 ) ); // (255 255, 255) is white!
this.pictureBox1.Image = bmp;
this.pictureBox1.BackColor = Color.Transparent; //makes humbly only your object!