1

我有一个 JPG 图像,并将它放在一个表格的图片框中,但是,它看起来像这样:

在此处输入图像描述

我怎样才能使图片的白色部分消失,只出现彩色部分?

4

2 回答 2

4

您可以在 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

于 2013-04-10T00:52:46.430 回答
1

尝试

    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!
于 2013-04-10T00:48:03.360 回答