简体   繁体   中英

C# - Convert Jpg to Png with index transparency

I need to efficiently convert a JPG image to a PNG image with index transparency. Do you know if this is possible (or have code) to do this?

Notes: Index-transparency is used to make only one colour transparent (typically white) while alpha-transparency is used to make all colours in the image transparent.

Answer - Continued

Thanks for help. Here is the code I just tested.

Bitmap b = new Bitmap(Image.FromFile("c:\\input2.jpg"));
b.MakeTransparent(Color.White);
b.Save("c:\\output2.png", ImageFormat.Png);

It converts fine, but there are various hues of white and if you are considering making white borders around your image transparent, you will need to make all these hues of white transparent too.

cheers.

try this... for me it works

Bitmap b = Image.FromFile(/*Image*/);
b.MakeTransparent(Color.White);
g.DrawImage(b, new Point(0, 0));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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