Mahmoud
Mahmoud

Reputation: 11489

Get Current Pixel value using Scanline in Delphi

I am trying to get the current pixel in an image by a "OnMouseMove event" Using Scanline.

something equivalent to this:

Label1.Caption := IntToStr(Image1.Picture.Bitmap.Canvas.Pixels[X,Y]);

Any ideas ?

Upvotes: 2

Views: 3758

Answers (2)

kludg
kludg

Reputation: 27493

ScanLine returns a pointer to a packed array of pixels that constitutes one line of a bitmap. Using this pointer you can access these pixels fast.

ScanLine can't help if you need only one pixel.

Still you can use ScanLine here; assuming bitmap pixel format pf32bit:

Label1.Caption:= IntToStr(PIntegerArray(Image1.Picture.Bitmap.ScanLine[Y])^[X]);

Upvotes: 6

Mason Wheeler
Mason Wheeler

Reputation: 84650

Scanlines are useful for quickly scanning the entire line, like in your other post. But if you want to get an arbitrary single pixel, the best way to do it is to use the code you've already got.

Upvotes: 2

Related Questions