Show *any* graphics as Glyph on a SpeedButton TBitBtn and TSpeedButton accept only BMP pictures, if you have some other picture format, like ICO or JPG, (in an Image component) you want to show as a Glyph, you'll need to "transform" it to Bitmap, here's how: |
Rotate Bitmap (any angle, any center of rotation) Here's how to rotate a TBitmap at any angle:Const PixelMax = 32768;Type pPixelArray = ^TPixelArray; TPixelArray = Array[0..PixelMax-1] Of TRGBTriple;Procedure RotateBitmap_ads( SourceBitmap : TBitmap; out Des... |
TImage.Bitmap fade out Put a TImage (Image1) on a Delphi form and load a bitmap of 24 bits or 32 bits in it; put a TButton (Button1) and put this code in its OnClick event:procedure TForm1.Button1Click(Sender: TObject) ; procedure FadeOut(const BMP:TImage; Pause:integer) ;... |
TDesktopCanvas - draw on Windows Desktop This canvas class allows you to access the Windows Desktop, and draw on it.type TDesktopCanvas = class(TCanvas) private DC : hDC; function GetWidth:Integer; function GetHeight... |
TColor to HTML color Put a TColorDialog (ColorDialog1), a TLabel (Label1) and a TButton (Button1) in your form, and assign the Button1.OnClick procedure as follows:procedure TForm1.Button1Click(Sender: TObject) ; function ColorToHtml(DColor:TColor):string; var ... |
Rotating Text Here is an example of text output that is rotated 45 degrees: procedure TForm1.Button1Click(Sender: TObject) ; var lf : TLogFont; tf : TFont; begin with Form1.Canvas do begin Font.Name := 'Arial'; Font.Size ... |
Get Cursor Image (draw it on a Canvas) The DrawCursor procedure draws a current cursor image on ACanvas at the Position point: procedure DrawCursor (ACanvas:TCanvas; Position:TPoint) ; var HCursor : THandle; beg... |
Paint a Form with a tiled bitmap image Here's how to draw tiled bitmap image on a Form:type TForm1 = class(TForm) procedure FormCreate(Sender: TObject) ; procedure FormPaint(Sender: TObject) ; procedure FormClose(Sender: TObje... |
Is Point in Polygon? This solution checks how many times you cross a line to pass from point X,Y to the edge of the polygon...function PtInPoly(const Points: Array of TPoint; X,Y: Integer): Boolean;var Count, K, J : Integer;begin Result := False; Count := Length(Po... |
Implementing a lasso drawing technique Here's one approach to drawing a lasso rectangle using Delphi:1. In the OnMouseDown event for the formthat you are 'lasso-ing' controls on:bMarquee := True;ptOrigin := Point(X,Y) ;ptMove := Point(X,Y) ;Pen.Color := clBlack;Pen.Width := 1;Pen.Style := psDas... |
Grayscaling a bitmap ? This example uses an averaging mechanism to obtain grayscale intensity on a pixel-by-pixel basis. Specifically, it averages the Red, Green and Blue component values of a color and assigns that value back to each RGB component. Usage: GrayScale(Image1.Pictu... |
Convert a BMP to a JPG You can easily convert a BMP image to a JPG (JPEG) image:{Usage:BMPtoJPG('mybitmap.bmp','myjpeg.jpg')}function BMPtoJPG (var BMPpic, JPGpic: string):boolean;var Bitmap: TBitmap; JpegImg: TJpegImage;begin Result:=False; ... |
How to convert HIcon to TIcon ? Many Windows API functions return a HIcon value (handle to Icon). Here's how to "convert" a HIcon to TIcon (object) For example, when using ExtractIcon to get icon from file, the resulting value is of the HICON type. The answer is: Create a TIcon object an... |
Extract an icon from an Windows application and paint on a Form This tip shows how to extract the associated icon and draw it into a small area of the form (e.g. Notepad icon)?procedure TForm1.Button1Click(Sender: TObject) ; var IconIndex : word; h : hIcon; begin IconIndex := 0; h:=ExtractAs... |
How to draw transparent text on Windows Desktop Here's how to draw transparent text on the Windows Desktop: { Usage: DrawTextOnDesktop('About Delphi Programming'): } procedure DrawTextOnDesktop(TextToDraw: string) ; var Handle: HWND; Dc: HDC; ACanvas: TCanvas; begin Ha... |
How to draw rotated text How to draw rotated textThis example creates a rotated font and displays it on the form by assigning the handle of the rotated to the Form’s Canvas Font via the Font’s Handle property. Rotating fonts is a straightforward process, so long as the Windows Fon... |
How to convert an ICO to a BMP If you have an icon file (ICO) and want to convert it to a bitmap image, use the following code: Procedure IcoToBmp; var Icon : TIcon; Bitmap : TBitmap; begin Icon := TIcon.Create; Bitmap := TBitmap.Create; Icon.LoadFromF... |
How to Convert Pixels to Millimeters If you need to convert pixel value to millimeters (inches, centimeters, etc.) use the code provided here.The code uses the API function GetDeviceCaps to get the metrics you need.procedure PixelsPerMM( canvas: TCanvas; var x, y: sing... |
How to capture Windows Desktop to Bitmap Here's a piece of Delphi code capable of capturing the Windows Desktop image into a TBitmap object:procedure ScreenShot(DestBitmap : TBitmap) ; var DC : HDC; begin DC := GetDC (GetDesktopWindow) ; try DestBitmap.Width := GetDevi... |
Cut a rectangle from an Image to Clipboard Cutting a graphic to the Clipboard is like copying it, but you also erase the graphic from the source.procedure CutToClipboard (AnImage:TImage; ARect:TRect) ;var b:TBitmap;begin |
Convert TColor to Hex & Hex to TColor Here are two simple functions to convert color values from TColor to Hex (HTML) and vice versa:function TColorToHex(Color : TColor) : string;begin Result := IntToHex(GetRValue(Color), 2) + IntToHex(GetGValu... |
Does my CD-ROM drive contain an audio CD? We can use the Windows API function GetDriveType() to test if the drive is a CD-ROM drive then use the Windows API function GetVolumeInformation() to test if the VolumeName is 'Audio CD'.function IsAudioCD(Drive : char) : bool;var DrivePath : s... |
Convert a mapped drive to a full UNC path Universal/Uniform Naming Convention. A UNC path describes the location of a volume, directory, or file.The format for a UNC path is \servervolumedirectoryfile and is not case-sensitive. For example: \Shared1_svrShared1WGroupsNetworkOrders.xlsR... |
Checking If File Is In Use IsFileInUse will return true if the file is locked for exclusive access. It would fail if the file doesn't exist at all. function IsFileInUse(fName : string) : boolean;var HFileRes : HFILE;begin Result := false; if no... |
Browse for Computers, Folders, Files and Printers By using the SHBrowseForFolder Windows API function and Delphi we can invoke a Windows system dialog used to browse for files and folders on users hard drive as well as network computers and printers. First, let's look at what SHBrowseForFolder needs. Here... |
How to draw Transparent Text on bitmap You can set transparent mode by calling SetBkMode function.procedure TForm1.Button1Click(Sender: TObject);begin with Image1.Picture.Bitmap.Canvas do begin Font.Color := clBlue; Brush.Style := bsclear;  ... |
How Do I Remove The Application Icon From The Taskbar? To remove the icon from the taskbar, you need to call a Windows API call:BOOL ShowWindow(HWND hwnd,int nCmdShow);Delphi makes it very easy to use this command. All you need to do is supply the Application.handle and SW_HIDE to remove the icon from the task... |
How To Show The Print Dialog And Print Text Files This code show an example of how to print a text of a RichEdit component.unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls; type TForm1 = class(TForm) ... |
How To Make An Animated Application Icon Show how to create an animated icon in your programvar icon1:Boolean; ... procedure TForm1.Timer1Timer(Sender: TObject); begin if icon1=false then begin Application.icon:=Image1.Picture.Icon; icon1:=tru... |
How To Pass The Focus To The Next/prior Control Shows how to activate the next or prior control in a formnext control: SendMessage(Form1.Handle, WM_NEXTDLGCTL, 0, 0); prior control: SendMessage(Handle, WM_NEXTDLGCTL, 1, 0); |