Page 1 of 1

Get the pointer to Image Data...

PostPosted: June 22nd, 2006, 10:31 am
by hadipardis
Hi. I am looking for a faster way than scanline to access image data. I know it is possible to do so by using pointer operation. For example I need to get a pointer to the fisrt pixel of the image. To do so, I use scanline , but I have some difficulties with it, for instance I tried the following code:
Code: Select all
 var PixelPointer,StartPointer:PByte
     b:byte;

 Bmp.Width:=640;
 Bmp.Height:=640;
 Bmp.PixelFormat:=pf24bit;// Pixel order: RGB RGB RGB ....

 StartPointer:=Bmp.ScanLine[0];
 PixelPointer := pointer(integer(StartPointer)+10*width+5);//pixel[5,10]
 Move(PixelPointer^, b, 1);  <<EAccessViolation!!!


But it raised an EAccessViolation exception. Do you know what is the problem? I want to get the RGB value of each pixel inside the image. Anyway, do you know any other way for obtaining the pointer to the image data? Thanks

PostPosted: June 22nd, 2006, 12:47 pm
by Kambiz
Bits of some bitmaps are arranged upside down. In this case, the first pixel is the bottom-left pixel.

Code: Select all
FirstPixel := Bitamp.ScanLine[Bitmap.Height - 1];