Results 1 to 5 of 5

Thread: SetPixel is not supported for images with indexed pixel formats.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    513

    SetPixel is not supported for images with indexed pixel formats.

    Hello: I receive this error when trying to SET the color of a pixel. My images that I'm loading must be in black and white and therefore, I save them as bmp type. I'm looping through my pixels and if i find ones that are black, I determine if they are edge points. If yes, I want to change their pixel color to Red:

    For X = 1 To myBmp.Width - 1 'Gets the width, in pixels, of this Image.
    i = 0
    For Y = 1 To myBmp.Height - 1 'Gets the height, in pixels, of this Image.
    Select Case myBmp.GetPixel(X, Y).R 'Gets the color of the pixel
    Case 255 'if white, don't do anything.
    Case Else
    'GET OUTTER EDGE POINTS
    'LOOK NORTH
    ' If (X <> 0 And Y <> 0) Then
    If myBmp.GetPixel(X, Y + 1).R = 255 Then
    IsOutterPerimeter = True
    End If
    'LOOK SOUTH
    If myBmp.GetPixel(X, Y - 1).R = 255 Then
    IsOutterPerimeter = True
    End If
    'LOOK EAST
    If myBmp.GetPixel(X - 1, Y).R = 255 Then
    IsOutterPerimeter = True
    End If
    'LOOK WEST
    If myBmp.GetPixel(X + 1, Y).R = 255 Then
    IsOutterPerimeter = True
    End If
    ' End If


    If IsOutterPerimeter = True Then
    'THIS IS THE LINE IT BOMBS ON myBmp.SetPixel(X, Y, System.Drawing.Color.Red)
    End if

    Has anyone else experienced this?
    Any ideas would be appreciated.
    Thanks,
    Proctor

  2. #2
    New Member
    Join Date
    Dec 2008
    Posts
    2

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

    im having the exact same problem just now. did you manage to resolve this or can any one else point me in the right direction?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

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

    What type of image was the Image object created from? You can only use SetPixel on formats that store data on a per pixel basis. Any formats that create each pixel on the fly based on an equation will not be able to set the colour of an individual pixel. For instance, if you draw a black line and your image format stores each pixel then you can change one specific pixel to red. If, however, your image format stores the start point and the end point and generates the rest based on those then there's no way it can change only one of those intermediate pixels.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    New Member
    Join Date
    Dec 2008
    Posts
    2

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

    i was working with bmp file and was getting the indexing issue.

    ive just saved the file as a jpg and the setPixel method works with this.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

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

    I honestly don't know exactly what an indexed pixel format is but I think that, if you want to maintain your original image format, you can create a new Bitmap object with the same dimensions as your existing Image, create a Graphics object from it and then draw the original Image onto the Bitmap. I believe you should then be able to call SetPixel on the Bitmap.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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