c# Bitmap.Save transparancy doesn't save in png

前端 未结 10 1371
眼角桃花
眼角桃花 2020-12-03 15:38

I\'m trying to save a Bitmap class that has transparancy as a png file with transparancy. I\'m having no luck.

The bitmap has transparancy, it just doesn\'t save wi

10条回答
  •  一生所求
    2020-12-03 15:53

    Are you sure the pixel format of the Bitmap is System.Drawing.Imaging.PixelFormat.Format32bppArgb? I just stumbled on this question because I was having the same problem, but it was because I was loading an image which had no alpha component to its pixel format. I did

    Bitmap output = original.Clone(rect, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    

    and it properly saved the PNG with the alpha component.

    Also, if you're using MakeTransparent() be sure that the color you're making transparent exists in your image.

提交回复
热议问题