When loading BMP images with image, it is traditionally scanline, canvas.pixel, or API functions to use the pixel values of a certain point.
Since image can draw a BMP image, the BMP should contain the pixel value of this bitmap. To look for. I found it, sure.
Tbitmap's parent class is tgraphic,
Tbitmap = Class (tgraphic) private fimage:tbitmapimage; Fcanvas:tcanvas; Fignorepalette:boolean; Fmaskbitsvalid:boolean; Fmaskvalid:boolean; Ftransparentcolor:tcolor; Ftransparentmode:ttransparentmode; Falphaformat:talphaformat; Procedure changing (sender:tobject); Procedure Copyimage (Ahandle:hbitmap; Apalette:hpalette; dib:tdibsection); Procedure dibneeded; Procedure Freecontext; function Getcanvas:tcanvas;
Tgraphic's first private variable is fimage, fimage:tbitmapimage;
View Tbitmapimage
Tbitmapimage = Class (Tsharedimage) private fhandle:hbitmap; DDB or DIB handle, used for drawing fmaskhandle:hbitmap;//DDB handle Fpalette:hpalette; Fdibhandle:hbitmap; DIB handle corresponding to Tdibsection fdib:tdibsection; Fsavestream:tmemorystream; Save original RLE stream until image is modified Fhalftone:boolean; Fpalette is halftone; Don ' t write to file{$IF DEFINED (CLR)} fimageformat:timageformat;{ $ELSE} Fos2format:boolean; Write BMP file header, color table in OS/2 format{$IFEND} protected procedure freehandle; override; Public destructor Destroy; override;{ $IF DEFINED (CLR)} function Gethashcode:integer; override;{ $IFEND} end;
Fdib:tdibsection, that's what I need.
Type pdibsection = ^tdibsection; {$EXTERNALSYM Tagdibsection} tagdibsection = packed record dsbm:tbitmap; Dsbmih:tbitmapinfoheader; DSBITFIELDS:ARRAY[0..2] of DWORD; Dshsection:thandle; Dsoffset:dword; End; Tdibsection = tagdibsection; {$EXTERNALSYM Dibsection} Dibsection = tagdibsection;
Dsbm:tbitmap; Contains the pixel value. View Tbitmap.
Pbitmap = ^tbitmap; {$EXTERNALSYM Tagbitmap} Tagbitmap = packed record bmtype:longint; Bmwidth:longint; Bmheight:longint; Bmwidthbytes:longint; Bmplanes:word; Bmbitspixel:word; Bmbits:pointer; End; Tbitmap = Tagbitmap; {$EXTERNALSYM BITMAP} BITMAP = Tagbitmap;
Bmbits:pointer contains the pixel value of the bitmap.
How do I get this value?
This involves the question of how to get the private variables of the class
First step: Get Fimage, get the private variable method of the class one
The Ignorepalette property of Tbitmap is public and we can access it. Fignorepalette = Ignorepalette, indicating that we can find the Fignorepalette address through Ignorepalette, on the two
It's Fimage's address.
Fimage: = Pointer (@srcbmp. Ignorepalette); Dec (fimage, SizeOf (Tcanvas)-2);
Second step: Get Fdib, get the private variable method of class two
The Tbitmapimage class does not have any export functions, and the method is useless.
directly with the address.
fimage^ contains the memory start address of the Tbitmapimage class
fimage^ + 4 * 4 + 8 is Fdib's address.
Fdib: = Pointer (fimage^ + 24);
Good, you can access the private variables arbitrarily.
Two ways to access private variables of a class