Results 1 to 6 of 6

Thread: [RESOLVED] SetPixel is not supported for images with indexed pixel formats

  1. #1

    Thread Starter
    Lively Member cs_tx_usa's Avatar
    Join Date
    Dec 2007
    Posts
    98

    Resolved [RESOLVED] SetPixel is not supported for images with indexed pixel formats

    Hi guys,

    I am loading an image on picturebox, then trying to paint some particular pixel but it does not work for the tif image that I have. I got the following error message "SetPixel is not supported for images with indexed pixel formats."

    Any help will be appreciated.

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: SetPixel is not supported for images with indexed pixel formats

    If the image you're trying to draw on has an indexed pixel format, then you need to create a bitmap object with a non-indexed pixel format and draw the tif image to it so you can draw on it.

    Example:

    vb Code:
    1. Dim tifimage as Image = Image.FromFile("C:\MyTif.TIF") 'indexed format image.
    2.  
    3. Dim NonIndexedImage as new Bitmap(tifimage.width,tifimage.height,System.Drawing.Imaging.PixelFormat.Format32bppPargB)
    4.  
    5. Dim g as Graphics = Graphics.FromImage(Ctype(NonIndexedImage,Image))
    6.  
    7. g.DrawImage(tifimage,0,0)
    8. g.dispose()
    9. tifimage.dispose()
    10.  
    11.  
    12. 'now you can setpixel on the tif image with the NonIndexedImage object.
    13.  
    14. NonIndexedImage.SetPixel(0,0,Color.Blue)
    15.  
    16. 'any further modifications
    17. ...
    18.  
    19. 'then save
    20.  
    21. NonIndexedImage.save("C:\MyTif.TIF",System.Drawing.Imaging.ImageFormat.Tiff)

    Hope this helps,

    Justin
    Last edited by MonkOFox; Mar 7th, 2011 at 02:52 PM.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Lively Member cs_tx_usa's Avatar
    Join Date
    Dec 2007
    Posts
    98

    Re: SetPixel is not supported for images with indexed pixel formats

    Thank you, Justin for your help. It works now.
    I just added a button to the program to clear the modified image from picturebox.

    Code:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            PictureBox1.Image.Dispose()
        End Sub
    but unfortunately the image was not cleared. There is no error message either. I don't want the user to close the program and run it again in order to load another image. How can I do that?

    Thanks.

  4. #4
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: SetPixel is not supported for images with indexed pixel formats

    Try:

    PictureBox1.Image = Nothing

    You may have to refresh the picturebox control, but probably not.

    P.S.

    All .dispose does is release the resources that are handling the Image object (Locks and etc.). You need to do that, but just wanted to let you know.
    I think the picturebox loads the file into memory but if you write 'Dim img as Image = Image.FromFile(Path as string)', that would put a lock on the file and to remove it you
    would need to call .Dispose on that image object in order to get rid of that lock.

    Justin
    Last edited by MonkOFox; Mar 8th, 2011 at 09:18 AM.
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  5. #5

    Thread Starter
    Lively Member cs_tx_usa's Avatar
    Join Date
    Dec 2007
    Posts
    98

    Re: SetPixel is not supported for images with indexed pixel formats

    Thanks Justin. It works like a charm. I appreciated your help.

  6. #6
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: [RESOLVED] SetPixel is not supported for images with indexed pixel formats

    No problem man, glad you got it working : ).

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width