I am using the GDI+ library for Delphi 6 by progdigy.com .
I loaded an image using TGPImage.Create(AFilename)
.
The question is, how can I query a single pixel (RGBA values)? The object TGPImage does not seem to have something like that. The documentation in the library only links to the Microsoft documentation of GDI+, which is a broken link by now.
PS: I can draw the image by using
TGPGraphics.Create(PaintBox1.Canvas.Handle).DrawImage(Image, GPRect(ALeft, ATop, AWidth, AHeight));
but I don't know if this helps since I need to query only the pixels without needing to draw the whole picture.
You can borrow the GetPixel
method from the TGPBitmap
class, which is used just for getting pixel colors. To implement this method, you will need to subclass the original TGPImage
class to get access to the protected NativeImage
field (holding the pointer to the Image
object).
Here is an example using interposer class:
uses
GDIPAPI, GDIPOBJ;
type
// we need to subclass the TGPImage to access the protected NativeImage field
TGPImage = class(GDIPOBJ.TGPImage)
public
function GetPixel(X, Y: Integer; out Color: TGPColor): TStatus;
end;
implementation
{ TGPImage }
function TGPImage.GetPixel(X, Y: Integer; out Color: TGPColor): TStatus;
begin
Result := SetStatus(GdipBitmapGetPixel(GPBITMAP(NativeImage), X, Y, Color));
end;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.