Problem with PNG images in C#

前端 未结 2 1581
醉梦人生
醉梦人生 2021-02-14 16:34

Working in Visual Studio 2008. I\'m trying to draw on a PNG image and save that image again.

I do the following:

private Image img = Image.FromFile(\"fil         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-14 17:29

    You cannot create a graphics from an indexed image format (PNG, GIF,...). You should use a Bitmap (file or convert your image to a bitmap).

    Image img = Image.FromFile("file.png");
    img = new Bitmap(img);
    newGraphics = Graphics.FromImage(img);
    

提交回复
热议问题