locked
Problem with "indexed pixel format" graphics RRS feed

  • Question

  • User-1597600490 posted
    I know alot of people have the problem with indexed pixel format. I hope someone can show me the solution to this.I am have problem with graphics with the following code giving the error: "A Graphics object cannot be created from an image that has an indexed pixel format." 'My code <%@ Page Language="vb" %> <%@ import namespace="system.drawing" %> <%@ import namespace="system.drawing.imaging" %> <%@ import namespace="system.drawing.drawing2d" %> <% ' initialise the web object Dim webC As New System.Net.WebClient() ' set the URL Dim strFilename as string strFilename="http://www.domain.com/graph.gif" ' create a bitmap based on the image from the URL Dim g = New System.Drawing.Bitmap(webC.OpenRead(strFilename)) response.contenttype="image/gif" dim gr as graphics = graphics.fromimage(g) ' create a New graphic object from the above bmp gr.smoothingMode = smoothingMode.antiAlias ' antialias objects '' draw the number on the image canvas in verdana 10pt font bold gr.drawString("ABC", New font("verdana",14,fontstyle.bold),systembrushes.windowtext, New pointF(2,2)) ' send the image to the viewer g.save(response.outputstream, g.rawformat) ' tidy up g.dispose() gr.dispose() webC = Nothing %>
    Sunday, January 23, 2005 5:31 PM

All replies

  • User-85647200 posted
    It seems like you should be saving the image using the GIF format ' send the image to the viewer g.save(response.outputstream, g.rawformat) should be ' send the image to the viewer g.save(response.outputstream, System.Drawing.Imaging.ImageFormat.Gif)
    Wednesday, February 2, 2005 11:53 PM
  • User-1372641848 posted
    ::It seems like you should be saving the image using the GIF format No that's not problem with his error . He is getting error because GDI + does not support creating graphics from indexed pixel formated image. check this Graphics.FromImage Method
    Thursday, February 3, 2005 12:34 PM
  • User-2088569288 posted
    GIF is an indexed pixel format. But you can convert it to a non-indexed format using the clone method. Then you can create the graphics object. Dim bitmap1 As New Bitmap(strpath, False) Dim bitmap2 As Bitmap = bitmap1.Clone(New Rectangle(0, 0, bitmap1.Width - 1, bitmap1.Height - 1), PixelFormat.Format24bppRgb) Dim gd As Graphics = Graphics.FromImage(bitmap2)
    Wednesday, February 16, 2005 4:04 PM