Problem with indexed pixel format/

Discussion in 'ASP .Net' started by jty202, Jan 23, 2005.

  1. jty202

    jty202 Guest

    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

    %>
    jty202, Jan 23, 2005
    #1
    1. Advertising

  2. This is intended behaviour. The error "A Graphics object cannot be created
    from an image that has an indexed pixel format." says it all.

    You need to create an image the same size as the original, get the Graphics
    object for it, draw the original onto the new Graphics object, draw your
    number and then save the newly created bitmap to the response stream.

    --
    Bob Powell [MVP]
    Visual C#, System.Drawing

    Find great Windows Forms articles in Windows Forms Tips and Tricks
    http://www.bobpowell.net/tipstricks.htm

    Answer those GDI+ questions with the GDI+ FAQ
    http://www.bobpowell.net/faqmain.htm

    All new articles provide code in C# and VB.NET.
    Subscribe to the RSS feeds provided and never miss a new article.





    "jty202" <> wrote in message
    news:...
    >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
    >
    > %>
    >
    >
    >
    Bob Powell [MVP], Jan 24, 2005
    #2
    1. Advertising

  3. jty202

    griggsfw

    Joined:
    Jun 16, 2008
    Messages:
    1
    Problem with Pixel Frmat

    Nice reply Bob Powell [MVP].

    I would think that if your response could be understood, then there'd have been no need to post the question!
    FWG
    griggsfw, Jun 16, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aliki
    Replies:
    3
    Views:
    740
    LostAtC
    Sep 24, 2004
  2. José Mª
    Replies:
    1
    Views:
    1,115
    David Zimmerman
    Jun 30, 2003
  3. Alex
    Replies:
    1
    Views:
    397
    Thomas Weidenfeller
    Apr 1, 2004
  4. Replies:
    3
    Views:
    719
  5. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,025
    Larry A Barowski
    Mar 19, 2008
Loading...

Share This Page