Getting grayscale values in array from a 8bpp image

Example requests & Code samples for GdPicture Toolkits.
Post Reply
Posts: 1
Joined: Tue Jul 15, 2008 5:07 pm

Getting grayscale values in array from a 8bpp image

Post by moranlf » Tue Jul 15, 2008 5:18 pm


I'm using VS2005 and writing a c# application for manipulating grayscale images in pgm format.
I managed to read the image from file to a GdPictureImaging object and display it in a Windows Form.
I now want to create a 2D array of the pixels' values. However, when I use GetPixelArray2D(ref imageArr,0,0,256,256), the resulting array's values are all very large negative values instead of 0-255 values.

Please help me convert a pgm image into a [0-255] 2d array

Thank you,
Moran Lefler

User avatar
Site Admin
Posts: 5696
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Getting grayscale values in array from a 8bpp image

Post by Loïc » Thu Jul 31, 2008 11:20 am


We added a method to do that within the last release: GetPixelArray8bpp1D()

See ... bpp1D.html

A sample to apply negative effect using GetPixelArray8bpp1D() & SetPixelArray8bpp1D() methods:

Code: Select all

Dim arPixel() As Byte
Dim X As Long
Dim Y As Long

Call Imaging1.GetPixelArray8bpp1D(arPixel, 0, 0, Imaging1.GetWidth, Imaging1.GetHeight)

For X = 0 To object.GetWidth - 1
    For Y = 0 To object.GetHeight - 1
        arPixel((Y * Imaging1.GetWidth) + X) = Not arPixel((Y * Imaging1.GetWidth) + X)
    Next Y
Next X
Call Imaging1.SetPixelArray8bpp1D(arPixel, 0, 0, Imaging1.GetWidth, Imaging1.GetHeight)


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests