Bitmap¶
Qualified name: delphivcl.Bitmap
- class Bitmap¶
Bases:
Graphic
TBitmap is an encapsulation of a Windows bitmap (HBITMAP), including its palette (HPALETTE). A bitmap is a powerful graphics object used to create, manipulate and store images in memory and as files on a disk. TBitmap contains an internal image of the bitmap graphic and automatically manages realization of the palette when drawn. To draw a bitmap on a canvas, call the Draw or StretchDraw methods of a TCanvas object, passing a TBitmap as a parameter. Creating copies of a TBitmap is very fast since the handle is copied rather than the image. If the image is modified and the handle is shared by more than one TBitmap object, the image is copied before the modification is performed (that is, copy on write).
Methods
Copies a new bitmap image to the bitmap object.
Vcl.Graphics.TBitmap.CanLoadFromStream inherits from Vcl.Graphics.TGraphic.CanLoadFromStream.
Create GDI bitmap for TBitmap if it doesn't already exist.
Loads a bitmap from the Clipboard into the bitmap object.
Loads the bitmap from a stream into the bitmap object.
Creates a local copy of the bitmap in Clipboard format.
Saves the bitmap to a stream.
Specifies the size of the bitmap.
Attributes
Indicates how reserved byte of each pixel is used in 32 bit bitmaps.
Canvas
ClassName
Returns the TObject.ClassName
Empty
Handle
HandleAllocated
HandleType
Height
IgnorePalette
IsAnimating
bool:
bool:
MaskHandle
Modified
Monochrome
Palette
PaletteModified
PixelFormat
ScaledDrawer
Returns the reference to the scaled drawer.
Pointer:
SupportsPartialTransparency
Indicate whether graphic supports partial transparency or an alpha channel.
Transparent
TransparentColor
TransparentMode
Width
- AlphaFormat¶
Indicates how reserved byte of each pixel is used in 32 bit bitmaps. Use AlphaFormat to change the way a TBitmap uses the reserved byte of each pixel in a 32bit Bitmap.
- Type:
AlphaFormat
- Assign(Source: Persistent) None ¶
Copies a new bitmap image to the bitmap object. Assign copies the bitmap image contained in Source to the bitmap object. If Source is not a bitmap, Assign calls the inherited Assign method, which can copy an image from any class that knows how to copy to a TBitmap object. If the bitmap needs to be changed, the actual bitmap image is copied before the changes are made (copy on write).
Note: An object of one type can always be assigned to another object of the same type. Also, the Source can be of type TPicture if the Graphic property of the picture is a bitmap.
- CanLoadFromStream(Stream: Stream) bool ¶
Vcl.Graphics.TBitmap.CanLoadFromStream inherits from Vcl.Graphics.TGraphic.CanLoadFromStream. All content below this line refers to Vcl.Graphics.TGraphic.CanLoadFromStream. CanLoadFromStream returns True when a specified stream contains a streamed image of a specific TGraphic subclass. The method uses current stream position, it does not change current stream position.
- Dormant()¶
- FreeImage()¶
- HandleNeeded()¶
Create GDI bitmap for TBitmap if it doesn’t already exist. HandleNeeded creates a GDI bitmap for the TBitmap if it doesn’t already exist.
- IsBottomTop¶
bool:
- LoadFromClipboardFormat(AFormat: int, AData: int, APalette: int) None ¶
Loads a bitmap from the Clipboard into the bitmap object. LoadFromClipboardFormat is called if the bitmap is registered with the TPicture object using the RegisterClipboardFormat method. LoadFromClipboardFormat replaces the current image with the data pointed to by the AData parameter. The palette for the bitmap is specified by the APalette parameter. The following code snippet shows how to load a bitmap from the clipboard and use that picture to draw on the canvas of the form.
Note: To load a bitmap into the clipboard, you can use the code snippet for the SaveToClipboardFormat method.
Delphi:
- uses
Vcl.Clipbrd;
procedure TForm1.Button1Click(Sender: TObject); var
Bitmap : TBitmap;
- begin
Bitmap := TBitMap.Create; try
Bitmap.LoadFromClipBoardFormat(cf_BitMap, ClipBoard.GetAsHandle(cf_Bitmap), 0); Canvas.draw(0,0,Bitmap);
- finally
Bitmap.Free; Clipboard.Clear;
end;
end;
C++:
#include <Vcl.Clipbrd.hpp>
- void __fastcall TForm1::Button1Click(TObject *Sender){
TBitmap* Bitmap; TClipboard* cb = Clipboard();
Bitmap = new TBitmap(); try{
Bitmap->LoadFromClipboardFormat(CF_BITMAP, cb->GetAsHandle(CF_BITMAP), 0); Canvas->Draw(0,0,Bitmap);
} __finally{
delete Bitmap; cb->Clear();
}
}
- LoadFromResourceID()¶
- LoadFromResourceName()¶
- LoadFromStream(Stream: Stream) None ¶
Loads the bitmap from a stream into the bitmap object. Use LoadFromStream to load the bitmap image from a stream. The Stream parameter specifies the stream from which to read the bitmap image. For example, use LoadFromStream to load a bitmap image from a BLOB stream that reads from a graphic field in a dataset.
- Mask()¶
- ReleaseHandle()¶
- ReleaseMaskHandle()¶
- ReleasePalette()¶
- SaveToClipboardFormat(Format: int, Data: int, APalette: int) None ¶
Creates a local copy of the bitmap in Clipboard format. Use SaveToClipboardFormat to copy the bitmap to a Clipboard format. The bitmap’s palette is returned in the APalette parameter, the format in the AFormat parameter, and a handle to the data in the AData parameter. Before the bitmap can be saved, an application must have registered the format with the TBitmap object using the RegisterClipboardFormat method. The following code snippet shows how to save a bitmap to the clipboard.
Note: To load a bitmap from the clipboard, you can use the code snippet for the LoadFromClipboardFormat method.
Delphi:
- uses
Vcl.Clipbrd;
procedure TForm1.Button1Click(Sender: TObject); var
MyFormat : Word; Bitmap : TBitMap; AData : THandle; APalette : HPALETTE;
- begin
Bitmap := TBitmap.Create; try
Bitmap.LoadFromFile(‘C:UsersPublicPicturesSample Picturesdesert.bmp’); Bitmap.SaveToClipBoardFormat(MyFormat, AData, APalette); ClipBoard.SetAsHandle(MyFormat,AData);
- finally
Bitmap.Free;
end;
end;
C++:
#include <Vcl.Clipbrd.hpp>
- void __fastcall TForm1::Button1Click(TObject *Sender){
TClipboard* cb = Clipboard(); unsigned short MyFormat; TBitmap* Bitmap; unsigned int AData; HPALETTE APalette;
Bitmap = new TBitmap(); try{
Bitmap->LoadFromFile(“C:\Users\Public\Pictures\Sample Pictures\desert.bmp”); Bitmap->SaveToClipboardFormat(MyFormat, AData, APalette); cb->SetAsHandle(MyFormat, AData);
} __finally{
delete Bitmap;
}
}
- SaveToStream(Stream: Stream) None ¶
Saves the bitmap to a stream. Use SaveToStream to write the bitmap image to the stream specified by the Stream parameter. For example, specify a TBlobStream object as the Stream parameter to save the bitmap image to a graphic field in a dataset.
- ScanLine¶
Pointer:
- SetSize(AWidth: int, AHeight: int) None ¶
Specifies the size of the bitmap. Use the SetSize method to set both the height and width of the bitmap. This results in better performance than setting the height and width separately.