繁体   English   中英

如何在PictureBox中将JPG的白色部分透明化

[英]How to White Part of JPG in PictureBox transparent

我有一个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=zh-CN&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!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM