"chuck" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
I load a bitmap using GDI+
now, I want to collect all the pixel values, (in RGB but
without the A component) onto a color array, say...
dim btmp1(,) as color
is there a method that can help me collect the pixel values
as quickly as possible (like one row at a time)?
what about setting (or changing) the pixel values back onto
the bitmap?
Yes, it's not easy, but this way is the fastest (without using DX or some
outside tool). You can use the LockBitmapBits function, which returns the
first element in an array of bits. Then use the Marshal.Copy function to
copy the array based on the assumed length and the first element. It's
sequential, so the array ends up looking something like this:
'// each pixel has 3 elements in the array
'// (R, G, B - but this changes if you have an
'// Alpha channel)
Pixel1_RedValue = RgbValues(0)
Pixel1_BlueValue = RgbValues(1)
Pixel1_GreenValue = RgbValues(2)
'// next 3 elements are for the second pixel
Pixel2_RedValue = RgbValues(3)
Pixel2_BlueValue = RgbValues(4)
Pixel2_GreenValue = RgbValues(5)
I have attached a class that inverts an image using the LockBitmap function
(which *does* use an Alpha channel). It's pretty clean, and should give you
a good jump start.
HTH,
Jeremy