Docs: LCL/intfgraphics. Fixes errors in example code. Issue #40970.

* Discussion in  https://forum.lazarus.freepascal.org/index.php/topic,67369.msg518241.html.

(cherry picked from commit 5b84fae03d)
This commit is contained in:
dsiders 2024-05-23 18:50:33 +01:00
parent 84ac965aeb
commit dae0c545d3

View File

@ -149,7 +149,9 @@ Author: Mattias Gaertner
</element> </element>
<element name="TLazIntfImage"> <element name="TLazIntfImage">
<short>Represents a graphical image.</short> <short>
Represents a graphical image.
</short>
<descr> <descr>
<p> <p>
TLazIntfImage is a <var>TFPCustomImage</var> descendant which stores the TLazIntfImage is a <var>TFPCustomImage</var> descendant which stores the
@ -167,59 +169,59 @@ deal with direct interface to the operating system at the pixel level.
1. Loading an .xpm file into a TBitmap: 1. Loading an .xpm file into a TBitmap:
</p> </p>
<code> <code>
var var
BmpHnd,MaskHnd: HBitmap; BmpHnd,MaskHnd: HBitmap;
Bitmap1: TBitmap; Bitmap1: TBitmap;
IntfImg1: TLazIntfImage; IntfImg1: TLazIntfImage;
Reader: TLazReaderXPM; Reader: TLazReaderXPM;
begin begin
// create a bitmap (or use an existing one) // create a bitmap (or use an existing one)
Bitmap1:=TBitmap.Create; Bitmap1:=TBitmap.Create;
// create the raw image // create the raw image
IntfImg1:=TLazIntfImage.Create(0,0); IntfImg1:=TLazIntfImage.Create(0,0);
// get the description for the current screen (bitsperpixel, depth, ...) // get the description for the current screen (bitsperpixel, depth, ...)
IntfImg1.GetDescriptionFromDevice(0); IntfImg1.DataDescription := GetDescriptionFromDevice(0);
// create the XPM reader // create the XPM reader
Reader:=TLazReaderXPM.Create; Reader:=TLazReaderXPM.Create;
// load the image // load the image
IntfImg1.LoadFromFile('filename.xpm',Reader); IntfImg1.LoadFromFile('filename.xpm',Reader);
// create the bitmap handles // create the bitmap handles
IntfImg1.CreateBitmap(BmpHnd,MaskHnd); IntfImg1.CreateBitmaps(BmpHnd,MaskHnd);
// apply handles to the Bitmap1 // apply handles to the Bitmap1
Bitmap1.Handle:=BmpHnd; Bitmap1.Handle:=BmpHnd;
Bitmap1.MaskHandle:=MaskHnd; Bitmap1.MaskHandle:=MaskHnd;
// clean up // clean up
Reader.Free; Reader.Free;
IntfImg1.Free; IntfImg1.Free;
// do something with the Bitmap1 // do something with the Bitmap1
... // ...
end; end;
</code> </code>
<p> <p>
2. Saving a TBitmap to an .xpm file: 2. Saving a TBitmap to an .xpm file:
</p> </p>
<code> <code>
var var
BmpHnd,MaskHnd: HBitmap; BmpHnd,MaskHnd: HBitmap;
Bitmap1: TBitmap; Bitmap1: TBitmap;
IntfImg1: TLazIntfImage; IntfImg1: TLazIntfImage;
Writer: TLazWriterXPM; Writer: TLazWriterXPM;
begin begin
... // ...
// create the raw image // create the raw image
IntfImg1:=TLazIntfImage.Create(0,0); IntfImg1:=TLazIntfImage.Create(0,0);
// load the raw image from the bitmap handles // load the raw image from the bitmap handles
IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle); IntfImg1.LoadFromBitmap(Bitmap1.Handle,Bitmap1.MaskHandle);
// create the XPM writer // create the XPM writer
Writer:=TLazWriterXPM.Create; Writer:=TLazWriterXPM.Create;
// save image to file // save image to file
IntfImg1.SaveToFile('filename.xpm',Writer); IntfImg1.SaveToFile('filename.xpm',Writer);
// clean up // clean up
Writer.Free; Writer.Free;
IntfImg1.Free; IntfImg1.Free;
... // ...
end; end;
}
</code> </code>
</descr> </descr>
<seealso/> <seealso/>