4

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.

2
  • 2
    That's not going to work well, since JPEG compression will destroy some of the color.
    – SLaks
    Nov 3, 2011 at 14:20
  • 1
    [This question][1] should contain all information you need for conversion. [1]: stackoverflow.com/questions/388677/…
    – PiRX
    Nov 3, 2011 at 14:25

1 Answer 1

5

try this... for me it works

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.