Generate transparent PNG c#

前端 未结 2 1999
走了就别回头了
走了就别回头了 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:21

    Take a look at Can you make an alpha transparent PNG with C#?

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题