Unit rpictool

Description

rpictool unit contains set of graphic functions working with BMP, JPG, PNG and color + gradients.

Updated version compatible with Delphi2010+.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TColorDefMap record type for one color definition

Functions and Procedures

function GetColorList(L: TStrings; AddExtendedColor, AddCustomColor, LocalizedName: boolean): integer;
function GetColorValue(idx: integer): TColor;
function GetColorName(idx: integer; LocalizedName: boolean): string;
function GetColorIdx(Color: TColor): integer; overload;
function GetColorIdx(const ColorName: string): integer; overload;
function ColorToString(Color: TColor; LocalizedName: boolean = false): string;
function StringToColor(const ColorStr: string): TColor;
function IsSameColor(Color1, Color2: TColor; Threshold_Proc: integer = 80): boolean;
procedure FontGetRotated(Font: TFont; Orientation: integer = 900);
procedure BiDi_ModifyRect(Canvas: TCanvas; var ARect: TRect);
procedure BiDi_FrameRect(Canvas: TCanvas; ARect: TRect; AColor: TColor = clNone);
procedure BiDi_DrawFocusRect(Canvas: TCanvas; ARect: TRect);
procedure DrawGradientV(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor);
procedure DrawGradientH(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor);
procedure DrawGradient(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor; Vertical: boolean; MaxSteps: integer);
function DrawDataBar(Canvas: TCanvas; ARect: TRect; Value, ValMin, ValMax: double; ColorFrom, ColorTo: TColor): double;
procedure DrawStatusBar(Canvas: TCanvas; ARect: TRect; Value, Steps: integer; BarType: TrStatusBarType; ColorAll, ColorDone: TColor);
procedure AnimateResize(W: TControl; NewRect: TRect);
procedure GetBitmapFromPicture(B: TBitmap; P: TPicture);
procedure DrawPictureCenter(Canvas: TCanvas; R: TRect; P: TPicture); overload;
procedure DrawPictureCenter(Canvas: TCanvas; R: TRect; P: TPicture; Stretch, Transparent: boolean); overload;
procedure DrawBmpAlign(Canvas: TCanvas; R: TRect; Bmp: TBitmap; Alignment: TAlignment; Margin: integer = 0);
procedure DrawBmpCenter(Canvas: TCanvas; R: TRect; Bmp: TBitmap); overload;
procedure DrawBmpCenter(Canvas: TCanvas; R: TRect; Bmp: TBitmap; Stretch: boolean); overload;
procedure DrawBmpCenter(DC: HDC; R: TRect; Bmp: TBitmap; Transparent: boolean); overload;
procedure DrawPictureTiles(Canvas: TCanvas; R: TRect; P: TPicture; Transparent: boolean);
procedure DrawBmpTiles(Canvas: TCanvas; R: TRect; Bmp: TBitmap);
procedure SmoothResizeBitmap(Bmp: TBitmap; MaxW, MaxH: integer; SmallEnlarge: boolean);
procedure SmoothResizeToBitmap(Src, Dst: TBitmap);
procedure SmoothResizePicture(P: TPicture; MaxW, MaxH: integer; SmallEnlarge: boolean);
procedure RotateBitmap(Bmp: TBitmap; Angle: double);
procedure RotateToBitmap(SrcBmp: TBitmap; DestBmp: TBitmap; Angle: double);
procedure RotatePicture(P: TPicture; Angle: double);
procedure ConvertBmpToIco(Bmp: TBitmap; Icon: TIcon; IconSize: integer);
procedure BitmapChangeColor(SourceBmp, DestBmp: TBitmap; NewColor: TColor; OldColor: TColor = clBlack);
function IsJPGSupported: boolean;
function IsPNGSupported: boolean;
function IsGraphicTypeValid(GraphicType: TrGraphicType): boolean;
function ReadPictureFromField(F: TField; P: TPicture): TrGraphicType;
function ReadBitmapFromField(F: TField; Bmp: TBitmap): TrGraphicType;
function WritePictureToField(F: TField; P: TPicture; FieldType: TrGraphicType): boolean;
function WriteBitmapToField(F: TField; Bmp: TBitmap; FieldType: TrGraphicType): boolean;
function LoadPictureFromFile(P: TPicture; const FileName: string; ShowErrorMessage: boolean = true): TrGraphicType;
function LoadBitmapFromFile(Bmp: TBitmap; const FileName: string; ShowErrorMessage: boolean = true): TrGraphicType;
function SavePictureToStream(P: TPicture; Stream: TStream; FileType: TrGraphicType): TrGraphicType;
function SaveBitmapToStream(Bmp: TBitmap; Stream: TStream; FileType: TrGraphicType): TrGraphicType;
function SavePictureToFile(P: TPicture; const FileName: string; FileType: TrGraphicType): TrGraphicType;
function SaveBitmapToFile(Bmp: TBitmap; const FileName: string; FileType: TrGraphicType): TrGraphicType;
function GetFileTypeFilterList(UseAllFormats: boolean): string;
function GetFileTypeExtension(GraphicType: TrGraphicType): string;
function GetFileTypeFromFileName(const FileName: string): TrGraphicType;
function OpenDlg_PictureFromFile(P: TPicture; const DefaultDir: string; DefaultGrType: TrGraphicType): TrGraphicType;
function SaveDlg_PictureToFile(P: TPicture; const DefaultDir: string; DefaultGrType: TrGraphicType): TrGraphicType;
function OpenDlg_GraphicFiles(D: TOpenDialog; MultiSelect, Execute: boolean; const DefaultDir: string; DefaultGrType: TrGraphicType): boolean;
function GetJPEGDimensions(const FileName: string; var X, Y: Word): boolean;
function WritePictureToJPGField(F: TField; P: TPicture; Quality: integer): boolean;
function WriteBitmapToJPGField(F: TField; Bmp: TBitmap; Quality: integer): boolean;
function SavePictureToJPGFile(P: TPicture; const FileName: string; Quality: integer): boolean;
function SaveBitmapToJPGFile(Bmp: TBitmap; const FileName: string; Quality: integer): boolean;

Types

TrGraphicType = (...);

Constants

cGradientStandardSteps = 100;
JPEGDefaultQuality = 100;
GraphicTypeLabel: array [TrGraphicType] of string = ('None', 'Error', 'BMP', 'JPG', 'PNG', 'EMF', 'Other');
ColorsDefArr: array [0 .. 20] of TColorDefMap = ((Value: clBlack; Name: sColorBlack; LocalizedName: sColorBlackLoc), (Value: clMaroon; Name: sColorMaroon; LocalizedName: sColorMaroonLoc), (Value: clGreen; Name: sColorGreen; LocalizedName: sColorGreenLoc), (Value: clOlive; Name: sColorOlive; LocalizedName: sColorOliveLoc), (Value: clNavy; Name: sColorNavy; LocalizedName: sColorNavyLoc), (Value: clPurple; Name: sColorPurple; LocalizedName: sColorPurpleLoc), (Value: clTeal; Name: sColorTeal; LocalizedName: sColorTealLoc), (Value: clGray; Name: sColorGray; LocalizedName: sColorGrayLoc), (Value: clSilver; Name: sColorSilver; LocalizedName: sColorSilverLoc), (Value: clRed; Name: sColorRed; LocalizedName: sColorRedLoc), (Value: clLime; Name: sColorLime; LocalizedName: sColorLimeLoc), (Value: clYellow; Name: sColorYellow; LocalizedName: sColorYellowLoc), (Value: clBlue; Name: sColorBlue; LocalizedName: sColorBlueLoc), (Value: clFuchsia; Name: sColorFuchsia; LocalizedName: sColorFuchsiaLoc), (Value: clAqua; Name: sColorAqua; LocalizedName: sColorAquaLoc), (Value: clWhite; Name: sColorWhite; LocalizedName: sColorWhiteLoc), (Value: clMoneyGreen; Name: sColorMoneyGreen; LocalizedName: sColorMoneyGreenLoc), (Value: clSkyBlue; Name: sColorSkyBlue; LocalizedName: sColorSkyBlueLoc) , (Value: clCream; Name: sColorCream; LocalizedName: sColorCreamLoc), (Value: clMedGray; Name: sColorMedGray; LocalizedName: sColorMedGrayLoc), (Value: clNone; Name: sColorCustom; LocalizedName: sColorCustomLoc));
ColorDefStandardCount = 16;
ColorDefExtendedCount = 4;
ColorDefCustomIdx = 20;

Description

Functions and Procedures

function GetColorList(L: TStrings; AddExtendedColor, AddCustomColor, LocalizedName: boolean): integer;

load list of Colors to list

function GetColorValue(idx: integer): TColor;

return color value according color index

function GetColorName(idx: integer; LocalizedName: boolean): string;

return color name or localozed name according color index

function GetColorIdx(Color: TColor): integer; overload;

return color index according color value

function GetColorIdx(const ColorName: string): integer; overload;

return color index according color name

function ColorToString(Color: TColor; LocalizedName: boolean = false): string;

return color name or hex string value according color value

function StringToColor(const ColorStr: string): TColor;

return color value according color string

function IsSameColor(Color1, Color2: TColor; Threshold_Proc: integer = 80): boolean;

compare two colors according provided threshold

procedure FontGetRotated(Font: TFont; Orientation: integer = 900);

set font orientation (rotate font)

procedure BiDi_ModifyRect(Canvas: TCanvas; var ARect: TRect);

modify Rect according to Canvas Orientation

procedure BiDi_FrameRect(Canvas: TCanvas; ARect: TRect; AColor: TColor = clNone);

draw FrameRect according to Canvas Orientation

procedure BiDi_DrawFocusRect(Canvas: TCanvas; ARect: TRect);

draw FocusRect according to Canvas Orientation

procedure DrawGradientV(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor);

draw vertical gradient to canvas

procedure DrawGradientH(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor);

draw horizontal gradient to canvas

procedure DrawGradient(Canvas: TCanvas; ARect: TRect; FromColor, ToColor: TColor; Vertical: boolean; MaxSteps: integer);

draw any gradient to canvas with definable number of steps

function DrawDataBar(Canvas: TCanvas; ARect: TRect; Value, ValMin, ValMax: double; ColorFrom, ColorTo: TColor): double;

draw ProgressBar to the rect (used by StringGrid and DBGrid)

procedure DrawStatusBar(Canvas: TCanvas; ARect: TRect; Value, Steps: integer; BarType: TrStatusBarType; ColorAll, ColorDone: TColor);

draw StatusBar to the rect (used by StringGrid and DBGrid)

procedure AnimateResize(W: TControl; NewRect: TRect);

animate resizing of Control

procedure GetBitmapFromPicture(B: TBitmap; P: TPicture);

assig picture to Bitmap or Draw to bitmap if Picture contains Metafile

procedure DrawPictureCenter(Canvas: TCanvas; R: TRect; P: TPicture); overload;

draw picture to center of rectangle

procedure DrawPictureCenter(Canvas: TCanvas; R: TRect; P: TPicture; Stretch, Transparent: boolean); overload;

draw picture to center of rectangle, definable strech and transparency

procedure DrawBmpAlign(Canvas: TCanvas; R: TRect; Bmp: TBitmap; Alignment: TAlignment; Margin: integer = 0);

draw bitmap aligned of rectangle

procedure DrawBmpCenter(Canvas: TCanvas; R: TRect; Bmp: TBitmap); overload;

draw bitmap to center of rectangle

procedure DrawBmpCenter(Canvas: TCanvas; R: TRect; Bmp: TBitmap; Stretch: boolean); overload;

draw bitmap to center of rectangle, definable strech and transparency

procedure DrawBmpCenter(DC: HDC; R: TRect; Bmp: TBitmap; Transparent: boolean); overload;

draw bitmap to center of rectangle by HDC instead of Canvas, definable transparency

procedure DrawPictureTiles(Canvas: TCanvas; R: TRect; P: TPicture; Transparent: boolean);

draw picture to rectangle as tiles

procedure DrawBmpTiles(Canvas: TCanvas; R: TRect; Bmp: TBitmap);

draw bitmap to rectangle as tiles

procedure SmoothResizeBitmap(Bmp: TBitmap; MaxW, MaxH: integer; SmallEnlarge: boolean);

resize bitmap to max width or height

procedure SmoothResizeToBitmap(Src, Dst: TBitmap);

resize one bitmap to another bitmap

procedure SmoothResizePicture(P: TPicture; MaxW, MaxH: integer; SmallEnlarge: boolean);

resize picture to max width or height

procedure RotateBitmap(Bmp: TBitmap; Angle: double);

rotate bitmap by defined angle

procedure RotateToBitmap(SrcBmp: TBitmap; DestBmp: TBitmap; Angle: double);

rotate one bitmap to another bitmap by defined angle

procedure RotatePicture(P: TPicture; Angle: double);

rotate picture by defined angle

procedure ConvertBmpToIco(Bmp: TBitmap; Icon: TIcon; IconSize: integer);

convert bitmap to icon

procedure BitmapChangeColor(SourceBmp, DestBmp: TBitmap; NewColor: TColor; OldColor: TColor = clBlack);

change bitmap pixels of one color to another color

function IsJPGSupported: boolean;

indicate whether JPG is supported

function IsPNGSupported: boolean;

indicate whether PNG is supported

function IsGraphicTypeValid(GraphicType: TrGraphicType): boolean;

indicate whether GraphicType is not Empty or Error

function ReadPictureFromField(F: TField; P: TPicture): TrGraphicType;

read field content and stored to Picture, return graphics type

function ReadBitmapFromField(F: TField; Bmp: TBitmap): TrGraphicType;

read field content and stored to Bitmap, return graphics type

function WritePictureToField(F: TField; P: TPicture; FieldType: TrGraphicType): boolean;

write picture content to field in defined graphics type

function WriteBitmapToField(F: TField; Bmp: TBitmap; FieldType: TrGraphicType): boolean;

write bitmap content to field in defined graphics type

function LoadPictureFromFile(P: TPicture; const FileName: string; ShowErrorMessage: boolean = true): TrGraphicType;

read file content and stored to Picture, return graphics type

function LoadBitmapFromFile(Bmp: TBitmap; const FileName: string; ShowErrorMessage: boolean = true): TrGraphicType;

read file content and stored to bitmap, return graphics type

function SavePictureToStream(P: TPicture; Stream: TStream; FileType: TrGraphicType): TrGraphicType;

write picture content to stream in defined graphics type, return final graphics type

function SaveBitmapToStream(Bmp: TBitmap; Stream: TStream; FileType: TrGraphicType): TrGraphicType;

write bitmap content to stream in defined graphics type, return final graphics type

function SavePictureToFile(P: TPicture; const FileName: string; FileType: TrGraphicType): TrGraphicType;

write picture content to file in defined graphics type, return final graphics type

function SaveBitmapToFile(Bmp: TBitmap; const FileName: string; FileType: TrGraphicType): TrGraphicType;

write bitmap content to file in defined graphics type, return final graphics type

function GetFileTypeFilterList(UseAllFormats: boolean): string;

return list of FileType filters used by Open/Save dialogs

function GetFileTypeExtension(GraphicType: TrGraphicType): string;

return file extension for defined GraphicType

function GetFileTypeFromFileName(const FileName: string): TrGraphicType;

return GraphicType according filename extension

function OpenDlg_PictureFromFile(P: TPicture; const DefaultDir: string; DefaultGrType: TrGraphicType): TrGraphicType;

select graphic file from disk and load content to picture, return GraphicType

function SaveDlg_PictureToFile(P: TPicture; const DefaultDir: string; DefaultGrType: TrGraphicType): TrGraphicType;

select file name and save picture content to file, return real GraphicType

function OpenDlg_GraphicFiles(D: TOpenDialog; MultiSelect, Execute: boolean; const DefaultDir: string; DefaultGrType: TrGraphicType): boolean;

initialize and optionaly execute OpenDialog

function GetJPEGDimensions(const FileName: string; var X, Y: Word): boolean;

read size of jpeg file

function WritePictureToJPGField(F: TField; P: TPicture; Quality: integer): boolean;

write picture content to field in jpg format and defined quality

function WriteBitmapToJPGField(F: TField; Bmp: TBitmap; Quality: integer): boolean;

write bitmap content to field in jpg format and defined quality

function SavePictureToJPGFile(P: TPicture; const FileName: string; Quality: integer): boolean;

write picture content to jpg file in defined quality

function SaveBitmapToJPGFile(Bmp: TBitmap; const FileName: string; Quality: integer): boolean;

write bitmap content to jpg file in defined quality

Types

TrGraphicType = (...);

list of graphics types

Values
  • gtNone
  • gtError
  • gtBMP
  • gtJPG
  • gtPNG
  • gtEMF
  • gtOther

Constants

cGradientStandardSteps = 100;

define number of steps for gradient background

JPEGDefaultQuality = 100;

define standard JPEG quality, used by WritePictureToField, 0..100 100=best quality but large file

GraphicTypeLabel: array [TrGraphicType] of string = ('None', 'Error', 'BMP', 'JPG', 'PNG', 'EMF', 'Other');

define name array of graphics types

ColorsDefArr: array [0 .. 20] of TColorDefMap = ((Value: clBlack; Name: sColorBlack; LocalizedName: sColorBlackLoc), (Value: clMaroon; Name: sColorMaroon; LocalizedName: sColorMaroonLoc), (Value: clGreen; Name: sColorGreen; LocalizedName: sColorGreenLoc), (Value: clOlive; Name: sColorOlive; LocalizedName: sColorOliveLoc), (Value: clNavy; Name: sColorNavy; LocalizedName: sColorNavyLoc), (Value: clPurple; Name: sColorPurple; LocalizedName: sColorPurpleLoc), (Value: clTeal; Name: sColorTeal; LocalizedName: sColorTealLoc), (Value: clGray; Name: sColorGray; LocalizedName: sColorGrayLoc), (Value: clSilver; Name: sColorSilver; LocalizedName: sColorSilverLoc), (Value: clRed; Name: sColorRed; LocalizedName: sColorRedLoc), (Value: clLime; Name: sColorLime; LocalizedName: sColorLimeLoc), (Value: clYellow; Name: sColorYellow; LocalizedName: sColorYellowLoc), (Value: clBlue; Name: sColorBlue; LocalizedName: sColorBlueLoc), (Value: clFuchsia; Name: sColorFuchsia; LocalizedName: sColorFuchsiaLoc), (Value: clAqua; Name: sColorAqua; LocalizedName: sColorAquaLoc), (Value: clWhite; Name: sColorWhite; LocalizedName: sColorWhiteLoc), (Value: clMoneyGreen; Name: sColorMoneyGreen; LocalizedName: sColorMoneyGreenLoc), (Value: clSkyBlue; Name: sColorSkyBlue; LocalizedName: sColorSkyBlueLoc) , (Value: clCream; Name: sColorCream; LocalizedName: sColorCreamLoc), (Value: clMedGray; Name: sColorMedGray; LocalizedName: sColorMedGrayLoc), (Value: clNone; Name: sColorCustom; LocalizedName: sColorCustomLoc));

define array of color records

ColorDefStandardCount = 16;
 
ColorDefExtendedCount = 4;
 
ColorDefCustomIdx = 20;
 

Author

Created

Nov 2010

Last Modified

May 2018


Generated by PasDoc 0.15.0.