<< Click to Display Table of Contents >> Navigation: »No topics above this level« Images |
Most of HTML components and THtDocument has OnGetImage event.
function(Sender: THtDocument; const Url: string; Element: TElement): THtBytes of object;
function should be thread-safe and return image data in TBytes or return nil if image cannot be loaded.
Embedded images, encoded using data URI, are processed internally, OnGetImage is not called.
When OnGetImage is not defined or return nil, THtDocument treats URL as file name and tries to load image from file.
In case URL contains only name without path, it is combined with CurrentFile property or application .exe path .
THtPanel has additonal default processing:
When URL is integer number and image list is assigned to Images property, URL is treated as index in image list.
When URL starts with 'http' or 'https', it is treated as web address.
When URL starts with '/form/' rest is treated as component name for current form. It can be TImage or TImageList and additional index, f.e. /form/ImageList1/2
For defining application-wide image sources, there is a THtVirtualImageSource class
THtVirtualImageSource = class
public
function GetImage(const URL: string; var ImageData: THtBytes; DPI: integer = 96): boolean; virtual; abstract;
end;
Each image source is registered with unique prefix, and can be used from any document. Example:
HtGlobal.RegisterVirtualImageSource('_resource', THtVirtualImageRes.Create);
There are following predefined sources / prefixes:
•_resource - load from resource
•_shellsmallicons - shell small icon
•_shelllargeicons - shell large icons
•_dialogicons - dalog icons
•_forms - application forms
Example of image URL:
<img src="_dialogicons/information"/>
Some HTML components has Images property, When image list is assigned, images can be referenced by index.
THtPanel has LazyLoading and BackgroundLoading properties.
In LazyLoading mode, images are loaded only when they are scrolled into view. BackgroundImageLoading enables image loading in a separate thread.
To embed all images into document (using data URI) call
procedure THtDocument.EmbedAllImages;
htimage and fmx.htimage units contains image converter implementation classes for image encoding and decoding.
IHtImageConverter = interface
function EMFtoSVG(Sender: TObject; var PictData: TBytes; Width, Height: integer; const AStyle: string = ''; ATextOnly: boolean = false): hstring;
procedure MakeTransparent(Sender: TObject;var Data: TBytes; var Ext: string; TransparentColor: cardinal);
function DecodeJPEG(const Data: THtBytes; var Res: THtBitmapData): boolean;
function DecodeJPEG2000(var Data: THtBytes): boolean;
function DecodePNG(const Data: THtBytes; var Res: THtBitmapData): boolean;
function DecodeGIF(const Data: THtBytes; var Res: THtBitmapData): boolean;
function EncodePNG(ABitmap: THtBitmapData; out Res: TBytes): boolean;
function EncodeJPEG(ABitmap: THtBitmapData; out Res: TBytes): boolean;
function HTMLtoPNG(Sender: TObject; const HTML: string; MaxWidth, MaxHeight, PageWidth, PageHeight: integer;
OnGetImage: THtGetImageData; out Res: TBytes; PagedMedia: boolean): boolean;
function WMZtoSVG(Sender: TObject; var PictData: TBytes; Width, Height: integer; const AStyle: string = ''): hstring;
function SVGtoEMF(Sender: TObject; const SVG: string; var Width, Height: integer): TBytes;
function HTMLtoSVG(const HTML, Style: hstring; Width, Height: integer; Paged: boolean = false): hstring;
end;
To get current image converter implementation use THtDocumentConverter.ImageConverter property