Make Transparent Image in png Format with .net GDI RRS feed

  • Question

  • User1062752276 posted


    I need to make transparent image in png format.

    Actually I am working on Live Image Editor.I have a problem to ganerate text image and make it transparent.I tried to generate text image in gif format and I was success but did not get clearity of image.I decided to create image in png format but in this case I can not make it transparent.

    Please can anybody help me regarding this?



    Monday, January 7, 2008 5:19 AM

All replies

  • User691546980 posted

     Hello I Faced This problem and I solved it By creating a blank PNG image with fixed size and then load it in the code and write what ever I want to then save it (Note that the blank PNG background is transparent)

    This is the code I used to make this operation

            Dim MyFont As New Font("Arial", 9)
            Dim Position As New PointF(5.0F, 5.0F)
            Dim PNGimage As System.Drawing.Image
            PNGimage = Image.FromFile(Server.MapPath("BlankImage.png"))
            Dim graphics As Graphics
            graphics = graphics.FromImage(PNGimage)
            graphics.DrawString("test", MyFont, Brushes.Black, Position)
            PNGimage.Save(Server.MapPath("WithTextImage.png"), ImageFormat.Png)

    I hope this is helpful to you


    Sunday, January 27, 2008 3:51 AM
  • User-290948741 posted


    I am facing the same problem. While the solution posted by kronass does work, it only produces an output image with the same dimensions as the input. My output image will be of a different dimension every time. Can this code be modified to achieve that? Is there an alternate way of generating transparent PNG with GDI+?


    Friday, September 19, 2008 11:56 PM