Generate transparent PNG c#

前端 未结 2 2000
走了就别回头了
走了就别回头了 2021-02-15 14:45

I have the function below to generate a sample logo. What I want to do is to return a transparent png or gif instead of a white background.

How can I do that?

         


        
2条回答
  •  旧巷少年郎
    2021-02-15 15:40

    You can do something like this:

    Bitmap bmp = new Bitmap(300, 300);
    Graphics g = Graphics.FromImage(bmp);
    
    g.Clear(Color.Transparent);
    g.FillRectangle(Brushes.Red, 100, 100, 100, 100);
    
    g.Flush();
    bmp.Save("test.png", System.Drawing.Imaging.ImageFormat.Png);
    

提交回复
热议问题