Bitmap Utils (24BIT Format Only)
Bmp_NewInst
Creates a new in-memory bitmap instance with the specified width and height.The resulting bitmap is ready for drawing or pixel manipulation.
Function Bmp_NewInst(Width, Height: Word): TBitmap;
Parameters
- Width: Word; the width of the bitmap in pixels.
- Height: Word; the height of the bitmap in pixels.
Return Value
Returns a new TBitmap object with the requested dimensions.Bmp_LoadPictureFromFile
Loads an image from a file into a new TBitmap object.Optionally applies PNG alpha transparency settings during conversion.
Function Bmp_LoadPictureFromFile(FileName: String; AssignPngAlpha: Boolean = False): TBitmap;
Parameters
- FileName: String; the full path to the image file to load.
- AssignPngAlpha: Boolean; if True, PNG alpha channel is preserved when applicable.
Return Value
Returns a TBitmap containing the loaded image content.Bmp_LoadPictureFromMS
Loads an image from a memory stream object into a TBitmap.The stream should contain valid picture data in a supported format.
Function Bmp_LoadPictureFromMS(HmemStream: TObject): TBitmap;
Parameters
- HmemStream: TObject; a memory stream instance containing image data (e.g. TMemoryStream).
Return Value
Returns a TBitmap initialized with the content of the memory stream.Bmp_Save_Into_FileType
Saves a bitmap to a file in a format determined by the file extension.JPEG quality can be controlled when saving to JPG files.
Procedure Bmp_Save_Into_FileType(Image: TBitmap; FileName: String; JpgQuality: Byte = 100);
Parameters
- Image: TBitmap; the bitmap image to be saved.
- FileName: String; the target file path, including extension.
- JpgQuality: Byte; quality factor for JPG output (1–100).
Bmp_DrawImage
Draws a source bitmap onto a target bitmap at the specified coordinates.This is a direct blit operation using pixel copy from one image to another.
Procedure Bmp_DrawImage(CONST X, Y: Integer; CONST Source, Target: TBitmap);
Parameters
- X: Integer; the horizontal position in the target bitmap.
- Y: Integer; the vertical position in the target bitmap.
- Source: TBitmap; the bitmap image to draw.
- Target: TBitmap; the destination bitmap where the image will be drawn.
Canvas_Copy
Copies a rectangular region from one canvas to another.Both source and target canvas objects must be valid and initialized.
Procedure Canvas_Copy(CONST X,Y,W,H,SrcX,SrcY: Integer; CONST Source, Target: TCanvas);
Parameters
- X: Integer; horizontal position in the destination canvas.
- Y: Integer; vertical position in the destination canvas.
- W: Integer; width of the area to copy.
- H: Integer; height of the area to copy.
- SrcX: Integer; source horizontal start point.
- SrcY: Integer; source vertical start point.
- Source: TCanvas; the canvas to copy from.
- Target: TCanvas; the canvas to copy into.
Bmp_Brighter
Increases the brightness of a specific rectangular region within a bitmap.The adjustment is done in-place on the source image.
Procedure Bmp_Brighter(Source: TBitmap; Amount: Double; OnRect: TRect);
Parameters
- Source: TBitmap; the image to be brightened.
- Amount: Double; the brightness factor to apply (typically 0.0 to 1.0).
- OnRect: TRect; the area within the bitmap to modify.
Bmp_Brighter_Into_New_Instance
Creates a new bitmap instance by applying brightness enhancement to the source image.The original image remains unchanged.
Function Bmp_Brighter_Into_New_Instance(Source: TBitmap; Amount: Double): TBitmap;
Parameters
- Source: TBitmap; the image to process.
- Amount: Double; the brightness factor to apply.
Return Value
Returns a new TBitmap with the adjusted brightness applied.Bmp_Darker
Decreases the brightness of a specified rectangular area within a bitmap.Applies a darkening effect in-place on the source image.
Procedure Bmp_Darker(Source: TBitmap; Amount: Double; OnRect: TRect);
Parameters
- Source: TBitmap; the image to darken.
- Amount: Double; the darkening factor to apply.
- OnRect: TRect; the area within the bitmap to modify.
Bmp_GrayScale
Applies grayscale conversion to the entire bitmap with optional brightness enhancement.Modifies the source image directly.
Procedure Bmp_GrayScale(Src: TBitmap; Brighter_Amount: Double = 0.5); Overload;
Parameters
- Src: TBitmap; the image to convert to grayscale.
- Brighter_Amount: Double; optional brightness scaling after grayscale (default is 0.5).
Bmp_GrayScale
Applies grayscale conversion to a specific rectangular area of a bitmap.Includes optional brightness scaling for enhanced visibility.
Procedure Bmp_GrayScale(Src: TBitmap; DstRect: TRect; Brighter_Amount: Double = 0.5); Overload;
Parameters
- Src: TBitmap; the bitmap to modify.
- DstRect: TRect; the area to apply grayscale within.
- Brighter_Amount: Double; optional brightness scaling (default is 0.5).
Bmp_Blend
Blends two source bitmaps into a destination bitmap using the specified ratio.Pixels are linearly interpolated based on the Amount value.
Procedure Bmp_Blend(Src1, Src2, Dst: TBitmap; Amount: Double);
Parameters
- Src1: TBitmap; the first source image.
- Src2: TBitmap; the second source image.
- Dst: TBitmap; the destination bitmap to receive the blended result.
- Amount: Double; the blend ratio between Src1 and Src2 (0.0 to 1.0).
Bmp_Blend_Element_Into_Bmp
Blends an overlay bitmap into another bitmap at a specified position with transparency control.Used to superimpose effects, logos, or elements with fading.
Procedure Bmp_Blend_Element_Into_Bmp(SrcDst, Element: TBitmap; Left, Top: Integer; Amount: Double);
Parameters
- SrcDst: TBitmap; the bitmap to be modified with the blended element.
- Element: TBitmap; the image to overlay.
- Left: Integer; horizontal position in the target bitmap.
- Top: Integer; vertical position in the target bitmap.
- Amount: Double; blend ratio (0.0 to 1.0).
Bmp_Blend_Element_Into_Canvas
Blends a bitmap element into a drawing canvas at a specified position with a given opacity.Useful for composing images directly to canvas-based controls or memory surfaces.
Procedure Bmp_Blend_Element_Into_Canvas(Canvas: TCanvas; Element: TBitmap; Left, Top: Integer; Amount: Double);
Parameters
- Canvas: TCanvas; the destination canvas for drawing the element.
- Element: TBitmap; the bitmap to blend into the canvas.
- Left: Integer; X position for drawing the element.
- Top: Integer; Y position for drawing the element.
- Amount: Double; blend factor for transparency (0.0 = fully transparent, 1.0 = fully opaque).
Bmp_Resize
Resizes the source bitmap into the destination bitmap dimensions.Performs a stretch blit from the source image into the destination bitmap.
Procedure Bmp_Resize(Src, Dst: TBitmap); Overload;
Parameters
- Src: TBitmap; the source image to resize.
- Dst: TBitmap; the destination bitmap which receives the resized result.
Bmp_Resize
Resizes a bitmap in-place to new specified dimensions.Creates a resized version of the original and replaces the input bitmap with it.
Procedure Bmp_Resize(VAR Src_And_Dst: TBitmap; NewWidth, NewHeight: Integer); Overload;
Parameters
- Src_And_Dst: TBitmap; the image to resize, replaced with the result.
- NewWidth: Integer; the target width for resizing.
- NewHeight: Integer; the target height for resizing.
Bmp_Resize_And_Draw_On_Canvas
Resizes a source bitmap and draws it onto the given canvas within the specified rectangle.Used for displaying a scaled version of the image directly on a canvas surface.
Procedure Bmp_Resize_And_Draw_On_Canvas(Src: TBitmap; Dst: TCanvas; DstRect: TRect);
Parameters
- Src: TBitmap; the bitmap to draw.
- Dst: TCanvas; the target canvas to receive the image.
- DstRect: TRect; the area on the canvas where the image will be drawn, stretched as needed.
Bmp_Resize_Keep_Aspect_Ratio_Fixed
Resizes a bitmap while maintaining its original aspect ratio.The image is centered and optionally filled with a background color.
Procedure Bmp_Resize_Keep_Aspect_Ratio_Fixed(Src, Dst: TBitmap; Center: Boolean; BackColor: TColor);
Parameters
- Src: TBitmap; the source bitmap to resize.
- Dst: TBitmap; the destination bitmap that receives the resized image.
- Center: Boolean; if True, the image is centered within the destination area.
- BackColor: TColor; background color used to fill empty space if aspect ratio leaves margins.
Bmp_Resize_Keep_Aspect_Ratio_Modify_Dst_Size
Resizes a bitmap while preserving aspect ratio, and updates the destination bitmap size accordingly.The destination bitmap is resized to fit the scaled source image exactly.
Procedure Bmp_Resize_Keep_Aspect_Ratio_Modify_Dst_Size(Src, Dst: TBitmap);
Parameters
- Src: TBitmap; the source bitmap to resize.
- Dst: TBitmap; the destination bitmap, resized to match the adjusted aspect ratio of the source.
Bmp_Crop
Crops a rectangular region from a bitmap in-place, discarding the rest of the image.The result replaces the original bitmap with the cropped section.
Procedure Bmp_Crop(Src_And_Dst: TBitmap; Crop: TRect);
Parameters
- Src_And_Dst: TBitmap; the image to crop, modified in-place.
- Crop: TRect; the rectangular region to extract from the source image.
Bmp_Crop_By_MaxSize
Crops a bitmap to fit within the specified maximum width and height.The cropped region starts from the top-left corner of the original image.
Procedure Bmp_Crop_By_MaxSize(VAR Src_And_Dst: TBitmap; MaxWidth, MaxHeight: Integer);
Parameters
- Src_And_Dst: TBitmap; the image to crop, modified directly.
- MaxWidth: Integer; maximum allowed width for the resulting bitmap.
- MaxHeight: Integer; maximum allowed height for the resulting bitmap.
Bmp_AntiAlias
Applies a simple anti-aliasing effect to reduce pixelation in the image.The effect is applied in-place and controlled by the strength percentage.
Procedure Bmp_AntiAlias(VAR SrcDst: TBitmap; Percent: Byte);
Parameters
- SrcDst: TBitmap; the image to be processed, modified in-place.
- Percent: Byte; smoothing intensity (0 to 100).
BMP_AntiAliasRect
Applies localized anti-aliasing on a specific rectangular region within a bitmap.Multiple retry passes may be performed to enhance the smoothing effect.
Function BMP_AntiAliasRect(Image: Tbitmap; Left, Top, Right, Bottom, RetryCount: Integer): Boolean;
Parameters
- Image: TBitmap; the bitmap containing the target region.
- Left: Integer; left edge of the rectangle.
- Top: Integer; top edge of the rectangle.
- Right: Integer; right edge of the rectangle.
- Bottom: Integer; bottom edge of the rectangle.
- RetryCount: Integer; number of processing passes to repeat.
Return Value
Returns True if the operation succeeded.Returns False if the image or parameters were invalid.
Bmp_Filter_Blue_Screen
Removes or filters out blue screen backgrounds based on RGB level thresholds.Often used for green/blue screen effects or chroma key masking.
Procedure Bmp_Filter_Blue_Screen(Src: TBitmap; BLevel, GLevel, RLevel: Byte);
Parameters
- Src: TBitmap; the image to be processed.
- BLevel: Byte; threshold for blue component.
- GLevel: Byte; threshold for green component.
- RLevel: Byte; threshold for red component.
Get_Rotated_Bmp
Generates a new bitmap by rotating the input image at the specified angle.The result is a newly allocated rotated image with transparency preserved if possible.
Function Get_Rotated_Bmp(Source: TBitmap; Angle: Double): TBitmap;
Parameters
- Source: TBitmap; the image to rotate.
- Angle: Double; the rotation angle in degrees (positive is clockwise).
Return Value
Returns a new rotated TBitmap instance based on the input image.Bmp_Capture_Screen
Captures the current screen into a bitmap image.Optionally minimizes the application window before capture to avoid overlay artifacts.
Function Bmp_Capture_Screen(Minimize_Application: Boolean): TBitmap;
Parameters
- Minimize_Application: Boolean; if True, the application minimizes itself before screen capture.
Return Value
Returns a TBitmap containing a full screenshot of the current display.Color_Light
Adjusts the brightness of a color by blending it with white based on a light factor.Used for UI highlighting or color visualization tweaks.
Function Color_Light(OriginalColor, Light: Integer): Integer;
Parameters
- OriginalColor: Integer; the base color to brighten.
- Light: Integer; the brightness factor (0–255).
Return Value
Returns the adjusted color as an integer in TColor format.IS_Dark_Color
Checks whether a given color is considered dark based on its brightness level.Used to decide between light or dark text over background colors.
Function IS_Dark_Color(OriginalColor: Integer): Boolean;
Parameters
- OriginalColor: Integer; the color to analyze.
Return Value
Returns True if the color is dark.Returns False if the color is light.
Generate_CAPTCHA
Generates a visual CAPTCHA image from a random character string.The CAPTCHA text is returned in the output parameter.
Function Generate_CAPTCHA(_Length: Byte; FontName: String; VAR CAPTCHA: String): TPngImage;
Parameters
- _Length: Byte; the number of characters to include in the CAPTCHA.
- FontName: String; the font to use for drawing the text.
- CAPTCHA: String; the output string representing the generated CAPTCHA content.
Return Value
Returns a TPngImage with the drawn CAPTCHA content.Bmp_Capture_TForm
Captures the visual contents of a TForm into a bitmap image.Supports cropping to exclude borders or status bar height.
Function Bmp_Capture_TForm(Src: TForm; VAR Dst: TBitmap; Border, StatusBarHeight: Cardinal): Boolean;
Parameters
- Src: TForm; the form to capture visually.
- Dst: TBitmap; output parameter that receives the captured image.
- Border: Cardinal; number of pixels to exclude from form borders.
- StatusBarHeight: Cardinal; number of pixels to exclude from bottom status bar.
Return Value
Returns True if capture was successful.Returns False otherwise.
Get_Icon_Html
Returns an HTML snippet representing a named icon with RTL or LTR direction.Intended for rendering UI icons in HTML-based environments.
Function Get_Icon_Html(_Name: String; CONST _RTL_Flag: Boolean): String;
Parameters
- _Name: String; the internal name of the icon to render.
- _RTL_Flag: Boolean; if True, applies right-to-left direction.
Return Value
Returns an HTML string with the formatted icon markup.ThBmpIcon
TheThBmpIcon
class is a visual component used to manage and draw bitmap-based icons by name.It supports logical icon lookup, RTL/LTR awareness, center-drawing, sizing, and image optimization.
Icons are stored in an internal collection and can be rendered on any canvas or returned as bitmaps.
The class also provides runtime performance improvements via indexing and lookup caching.
Public Procedures and Functions:
Runtime_Optimization
Performs runtime icon indexing optimization after loading.Typically invoked automatically by the Loaded method in release builds.
Procedure Runtime_Optimization;
Find_In_This_Collection
Searches for an icon by name within the current icon collection.Function Find_In_This_Collection(CONST _Name: String; CONST Mark_As_Called: Boolean): ThBmpIconItem;
Parameters
- _Name: String; the name of the icon to find.
- Mark_As_Called: Boolean; if True, the icon is marked as used.
Return Value
Returns a pointer to the matching ThBmpIconItem, or nil if not found.Find
Searches for an icon by name across the component context.This is the main public method for locating icons dynamically.
Function Find(CONST _Name: String; CONST Mark_As_Called: Boolean = True): ThBmpIconItem;
Parameters
- _Name: String; the name of the icon to locate.
- Mark_As_Called: Boolean; if True, marks the icon as used (default is True).
Return Value
Returns the ThBmpIconItem if found, otherwise returns nil.Bitmap
Returns the bitmap image for a given icon name and direction flag.Function Bitmap(_Name: String; CONST _RTL_Flag: Boolean = False): TBitmap;
Parameters
- _Name: String; the name of the icon to retrieve.
- _RTL_Flag: Boolean; if True, uses the right-to-left version of the icon (default is False).
Return Value
Returns a TBitmap instance of the requested icon.DrawCenter
Draws an icon centered within the given rectangle on the canvas.Procedure DrawCenter(CONST _Name: String; CONST X1, Y1, X2, Y2: Integer; TargetCanvas: TCanvas; CONST _RTL_Flag: Boolean);
Parameters
- _Name: String; the icon name to draw.
- X1: Integer; left boundary of the target rectangle.
- Y1: Integer; top boundary of the target rectangle.
- X2: Integer; right boundary of the target rectangle.
- Y2: Integer; bottom boundary of the target rectangle.
- TargetCanvas: TCanvas; the canvas on which to draw the icon.
- _RTL_Flag: Boolean; if True, flips the icon for right-to-left rendering.
Draw
Draws an icon at the specified location on a target canvas.Procedure Draw(CONST TargetCanvas: TCanvas; CONST X, Y: Integer; CONST _Name: String; CONST _RTL_Flag: Boolean);
Parameters
- TargetCanvas: TCanvas; the canvas where the icon should be drawn.
- X: Integer; the horizontal position of the icon.
- Y: Integer; the vertical position of the icon.
- _Name: String; the icon name to draw.
- _RTL_Flag: Boolean; True to draw in right-to-left mode.
SafeWidth
Returns the width of the specified icon, with optional padding added.Function SafeWidth(CONST _Name: String; CONST _Add_Pixels_If_Exists: Byte): Word;
Parameters
- _Name: String; the name of the icon.
- _Add_Pixels_If_Exists: Byte; extra padding to add if the icon is found.
Return Value
Returns the width of the icon plus any additional pixels requested.SafeHeight
Returns the height of the specified icon, with optional padding added.Function SafeHeight(CONST _Name: String; CONST _Add_Pixels_If_Exists: Byte): Word;
Parameters
- _Name: String; the name of the icon.
- _Add_Pixels_If_Exists: Byte; extra padding to add if the icon is found.
Return Value
Returns the height of the icon plus any additional pixels requested.SafeSize
Returns the full size (width and height) of the icon with optional padding.Function SafeSize(CONST _Name: String; CONST _Add_Pixels_For_Width, _Add_Pixels_For_Height: Byte): TSize;
Parameters
- _Name: String; the icon name.
- _Add_Pixels_For_Width: Byte; additional width to include in result.
- _Add_Pixels_For_Height: Byte; additional height to include in result.
Return Value
Returns a TSize structure with the calculated width and height.Properties:
Storage_Mode
Enables or disables storage mode for the icon component.Property Storage_Mode: Boolean Read FStorage_Mode Write FStorage_Mode Default False;
Return Value
Gets or sets the boolean flag indicating whether the component is in storage mode.Icons
Provides access to the internal icon collection.Each item in the collection represents a named icon.
Property Icons: ThBmpIconCollection Read FIcons Write FIcons;
Return Value
Gets or sets the icon collection associated with this component.ThBmpIconCollection
TheThBmpIconCollection
class manages a list of ThBmpIconItem
entries associated with a ThBmpIcon
component.It provides indexed access to items and supports standard collection operations such as adding and retrieving icons.
Public Procedures and Functions:
Add
Creates a new icon item and adds it to the collection.Function Add: ThBmpIconItem;
Return Value
Returns a reference to the newly createdThBmpIconItem
.Items
Provides indexed access to individual icon items within the collection.Property Items[Index: Integer]: ThBmpIconItem Read GetItem Write SetItem; Default;
Parameters
- Index: Integer; the position of the item in the collection.
Return Value
Gets or sets the icon item at the specified index.ThBmpIconItem
TheThBmpIconItem
class represents a single icon in a ThBmpIconCollection
.Each item stores a name, bitmap image, and optional direction flags for RTL and LTR usage.
This class is used internally by
ThBmpIcon
to manage icon resources.Public Procedures and Functions:
rt_Called
Marks whether this icon was accessed or used at runtime.This flag is used internally for optimization or debugging purposes.
Property rt_Called: Boolean;
Return Value
True if the icon has been requested or drawn during execution.False if it has not been accessed.
Bitmap
Contains the bitmap image associated with this icon.Property Bitmap: TBitmap;
Return Value
Gets or sets the graphical bitmap used to render this icon.Properties:
Name
Specifies the unique name of the icon within the collection.Property Name: String;
Return Value
Gets or sets the identifier used to refer to this icon in code or markup.PNG_Image
Stores the PNG image representation of the icon, allowing full alpha transparency.Used as an alternative to the Bitmap property when PNG format is preferred.
Property PNG_Image: TPngImage Read FPNG_Image Write Set_PNG_Image;