TBitmap, BMP, DIB
TBitmap
Delphi Graphics VCL/RTL page
| general info | 1. In D1/D2, a bitmap was a DIB (device independent bitmap)
after loading, but became a DDB (device dependent bitmap) on the first screen draw -- the
DIB was tossed and the DDB format was kept. The pixel format could (and usually did)
change across load/modify/save sequences. In D3, Danny Thorpe (Borland) reimplemented TBitmap to use a DIBSection to solve the load/modify/save problem present in D1/D2. The use of DIBs provided direct access to pixel memory (using the Scanline property) and the bitmap handle at the same time. 2. In D3/D4 if you load an RLE compressed bitmap, it is loaded as a DDB, but when it gets written out, it is written an an uncompressed (screen pixel format) DIB. 3. Getting a strange compile-time error with a TBitmap? There's a TBitmap defined in both the Windows and Graphics unit and they may be in the wrong order in your USES statement. Normally you want the one from the Graphics unit (put in last in your USES), unless you're directly using API functions.] 4. The standard windows glyphs are stored within comctl32.dll as bitmaps. 5. TBitmap is defined in both windows.pas and graphics.pas units. Since the compiler automatically recognizes the last one in the "Uses" statement, make sure "Graphics" follows "Windows" in the "Uses" statement. Example of comparing two TBitmaps and counting number of pixels that match and differ.
Bitmaps and InterBase BLOB Fields (TI 797D) Handling bitmap display (FAQ 2418D) [size
limitations] Delphi Pool TBitmap Tips How can I create a bitmap from an icon? (FAQ 2752D)
Patrick Martin's example TBitmap descendant using memory mapped files Background Bitmaps on Forms by Robert Vivrette Big Bitmap Viewer by Grahame Marsh Load Bitmap Resource by Ray Lischner. Look for bmpres10.zip www.tempest-sw.com/freeware or via ftp at ftp://ftp.tempest-sw.com/pub/delphi/bmpres10.zip Storing bitmaps as resources, pp. 525-531, Delphi Programming Problem Solver, Neil Rubenking "Displaying your bitmaps quickly", Delphi Developer's Journal, July 1998, pp. 12-15. (Double buffering using Pixels instead of Scanline. This technique is not very quick compared to using Scanline!) File 98Jul/DDJ9873.ZIP at ftp.zdjournals.com/ddj "Eliminate flicker when painting on a form or a TPaintBox control, " www.bcbdev.com/faqs/faq34.htm Mike Shkolnik's UseNet Post:
Bitmap to TGraphicField Rund um TBitmap efg's UseNet Post about how to create TList of TBitmaps |
| Assign | Borland example: ..\Delphi n\Demos\Doc\GraphEx.dpr Transparent property to work for a CoolBar background bitmap (FAQ 1390D) Extracting a Bitmap from A BLOB Field (TI 791D) Converting a BMP to a JPEG and Vice Versa (TI 4582D) efg's Note: There is a Very Subtle Bug/Feature in the Delphi 3/4 Assign when only using Scanline to access pixel data. Assign should always be a "deep copy" (all data copied) versus a "shallow copy" (only a pointer copied), but this isn't always true! The kludge fix is to copy a single pixel from one bitmap to the other using the Pixels property to force unique references. See Assign.Txt. (Fixed in D5) |
| Create/Free | Creating temporary canvas (FAQ 1277D)
Francesco Savastano's UseNet Post about initializing bitmap to specified color |
| Dormant | Problem with complex implementation that allows DDB and DIB Section
to exist simultaneously in Single TBitmap as described in UseNet
Post by Takuo Nakamura. This note gives an example of when Dormant is
needed.
Nick Hodges' UseNet Post answering "How does TBitmap.Dormant work?" Peter Haas' UseNet Post about using Bitmap.Dormant after setting PixelFormat to fix a problem in D1-D4 with the TBitmaInfoHeader efg's example of converting TIcon to TBitmap, as well as extracting the icon's "AND" bitmap mask and the "OR" color bitmap. [This is the first example that I needed "Dormant" but this solution only worked in Windows 2000. An alternate approach was needed for Windows 98. --efg] See the Cursor Overlay Lab report for another Dormant example. |
| FreeImage | Finn Tolderlund's UseNet Post about Scanline and FreeImage |
| HandleType (D3/D4) |
THandleType =
(bmDDB, bmDIB) In D3/D4 if you create a TBitmap and DO NOT assign either the PixelFormat or the HandleType, a DDB is created. If you set HandleType := bmDIB, or if you specify any PixelFormat (other than pfDevice), you get a DIB. A BMP loaded from a file is a DIB (HandleType = bmDIB). Problem with complex implementation that allows DDB and DIB Section to exist simultaneously in Single TBitmap as described in UseNet Post by Takuo Nakamura. This note gives an example of when HandleType is needed. |
| LoadFromFile | Transparent property to work for a CoolBar background bitmap
(FAQ 1390D) How can I place a bitmap in a metafile? (FAQ 1842D) See \Program Files\Borland\Delphi n\HELP\Examples\Bitmap\BMPFormU.PAS Using Bitmaps, p. 216, Delphi
Component Design by Danny Thorpe: |
| Mask | Shannon Broskie's UseNet Post with DrawTitleBarImage function |
| Monochrome | Setting Monochrome to TRUE on a pf24bit bitmap
changes the PixelFormat to pfDevice.
My observation is that all non-white colors become black when Monochome is set to TRUE on a pf24bit bitmap.
|
| Palette | efg's UseNet
Post about how to create pf8bit TBitmap with 256 shades of gray.
Also see Delphi Graphics Color Page |
| PixelFormat (D3/D4) | TPixelFormat = (pfDevice, pf1bit,
pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit, pfCustom); PixelFormat and Scanline are discussed at length in Manipulating Pixels With Delphi's ScanLine Property Peter Haas' UseNet Post about using Bitmap.Dormant after setting PixelFormat to fix a problem in D1-D4 with the TBitmapInfoHeader Ian Martin's UseNet Post about PhotoShop's problem with pf16bit bitmaps See also Monochrome. |
| Resource Files | See Resource Files on Delphi Graphics Algorithms page |
| SaveToClipboardFormat | The example in the D3 online help compiled
(with a warning), but the online help example of SaveToClipboardFormat has
never been quite right and does not compile (see efg's
UseNet Post about this).
Here's a version of the online example that will compile in D3..D7:
USES clipbrd; // I wish Borland showed what unit is needed in the help procedure TForm1.Button1Click(Sender: TObject); var
MyFormat : Word;
Bitmap : TBitMap;
AData : THandle;
APalette : hPalette; // Wrong in D3-D7 online example
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromFile('c:\Program Files\Common Files\Borland Shared\Images\Splash\256color\factory.bmp');
Bitmap.SaveToClipBoardFormat(MyFormat,AData,APalette);
ClipBoard.SetAsHandle(MyFormat,AData);
finally
Bitmap.Free;
end;
end;
|
| SaveToFile | Converting a BMP to a JPEG and Vice Versa (TI 4582D) |
| Scanline (D3) | The PixelFormat defines the layout of a Scanline. PixelFormat
and Scanline are discussed at length in Scanline Enigma working with pf24bit Bitmaps (fixed in D4.02 and D5) Finn Tolderlund's UseNet Post about Scanline and FreeImage See also Monochrome. |
| Transparent TransparentColor TransparentMode |
The Transparent property of a TBitmap works
only if you use the Draw method to draw it on a canvas. If Transparent
:= TRUE, and TransparentMode := tmAuto, then the
transparent color is the color of the bottom-leftmost pixel of the bitmap. If TransparentMode := tmFixed, then the transparent color is
defined by the TransparentColor property. Dynamically drawing a transparent image (FAQ 1794D) Also see "Transparency" in Section B of Delphi Graphics Algorithms. |
BMP and DIB File Formats
| File Format | Description/Comments | ||||||
| Archives |
Raize Button Glyphs Glyphs und Icons im Internet Images in BMP format -- 16800 images (8 MB) 9452 glyphs from Richey's Delphi-Box More than 400 glyphs from MS Office Applications Raize
Button Glyphs 1000 glyphs for free Links to various bitmap/icon collections |
||||||
| BMP | Bitmap and Metafile Functions, Tomes Graphical,
pp. 273-356 Windows Bitmap used with Microsoft Paint To create a RES file with Bitmaps: Loading Bitmaps and Cursors from RES files (TI 1081D) Example of comparing two TBitmaps and counting number of pixels that match and differ. efg's Resource Demo application shows how to use the following file types in resource files: BMP, ICO, JPG, GIF (requires Anders Melander's TGIFImage), EMF, TXT, AVI, WAV and cursors Peter Haas' UseNet Post about determining a bitmap's size without loading the complete TBitmap, and Joe Hecht's Reply Post with certain precautions Bitmap Orientation and biHeight biHeight and Video Formats in DirectShow (problem with inverted video
images) Scanline Tech Note explains accessing pixel data quickly for the various PixelFormats 24 bits/pixel to 8 bits/pixel bitmaps using the ReduceColors function. See Anders Melander's UseNet Post about using TGIFImage to reduce colors. RGB Formats
Resource-Grabber will scan the directories and drives on your computer and extract all Bitmaps, Glyphs (button images), Icons, Cursors, JPG/JPEG images, WAVE and RMI sound files as well as AVI video clips it finds inside the programs and DLL files in any directory of your choice. http://inner-smile.com/dl_res.htm Glyph Viewer facilitates the search in large Glyph directories. In a
list all bit-maps of a directory as well as their file names and creation dates are
displayed. The list can be sorted according to file names and creation dates. In a tree
representation you can select the desired directory. BMP Technical Tutorial: Microsoft's "Error 481: Invalid Picture" Err Viewing BMP File Danny Thorpe's UseNet Post
about RLE BMPs efg's PelsPerMeter example with GetPelsPerMeter procedure to return biXPelsPerMeter and biYPelsPerMeter values, and an example based on a UseNet Post by Peter Klein that returns these same values. Biff Kadidlehopper's UseNet Post to get/set the dpi in a bitmap file or bitmap image (the biXPelsPerMeter and biYPelsPerMeter values) The biXPelsPerMeter is a 4-byte integer at an offset of 38 bytes from the start of the file; biYPelsPerMeter is a 4-byte integer at an offset of 42 bytes from the start of the file. Example from Robert Poyntz with SpecialBMP routine to set the biXPelsPerMeter and biYPelsPerMeter values. SpecialGIF procedure by Robert Poyntz with biXPelsPerMeter and biYPelsPerMeter example. Supported by ImageLib www.imagelib.com |
||||||
| DIB |
Windows Device-Independent Bitmap
Delphi Programming & Assembly Language (DIBULTRA) Joe Hecht's UseNet Post with BltTBitmapAsDib procedure Chris Hill's UseNet Post explaining two ways the term DIB is used efg's examples of working with DIBs while converting Lead Tool's BitmapHandle to TBitmap Delphi Graphics Programming by Peter Dove and Don Peer in Delphi
Informant: DIBs. A class that provides easy access to Device Independent Bitmaps. Delphi Super Page: http://delphi.icm.edu.pl/ftp/d10free/dibs.zip Wie ist eine DIB aufgebaut (How a DIB is structured) Supported by ImageLib www.imagelib.com Non-Delphi: Using Device-Independent Bitmaps and Palettes http://support.microsoft.com/support/kb/articles/q72/0/41.asp "More Fun with MFC: DIBs, Palettes, Subclassing, and a Gamut of Reusable
Goodies", Part I (Jan 97),
www.microsoft.com/MSJ/0197/mfcp1/mfcp1.htm More Fun With MFC: DIBs, Palettes, Subclassing and a Gamut of Goodies,
Part II (Mar 97) More Fun with MFC: DIBs, Palettes, Subclassing, and a Gamut of Goodies,
Part III (Jun 97) |
| Conversion(s) | Description/Comments | ||||
| 411 to BMP | efg's 411 Lab Report to read .411 file and convert to a TBitmap | ||||
| AVI to BMPs | Eddie Shipman's UseNet Post with Example of how to convert the following "common" AVIs into BMPs: FindFolder, iFindFile, FindComputer, CopyFiles,iCopyFile, RecycleFile, EmptyRecycle, DeleteFile Toni Martir's notes
and complete VFW example (see ShevinE's improvement
below). (Note: to get Toni's complete example to compile in D3-D5, make sure
you can compile with USES OLE2: Use Lizard.AVI or another AVI file with Toni's example. ShevinE's improvements to Toni Martir's example (D3-D5 source). Saves AVI to BMP files as FrameXX.BMP. Includes VFW.PAS file used in Toni's example. (Requires USES OLE2 -- see above notes for details.) [Use Lizard.AVI or another AVI file.] efg's AVItoBMP example project (Delphi 3-5 source code). The "Jesus Lizard" AVI file shows a
lizard walking on water. VB Info: AVI to BMPs |
||||
| Bitmap to DIB Handle | Takuo Nakamura's UseNet Post with BitmapToDIBHandle routine | ||||
| BitmapHandle to/from TBitmap | efg's example of converting from Lead's BitmapHandle with a BMP to several formats including CMP, EPS, JPG, PCT, PCX, PNG, RAS, TGA, TIF, WMF, or from TBitmap to BitmapHandle | ||||
| BitmapToWMF | Procedure in ImageLib Suite DLL. Harm's UseNet Post about converting bitmap to EMF/WMF |
||||
| BMPs to AVI | Tilo Arnold's UseNet Post See Rob
Anderson's AVIBUILD. VB
Info: BMPs to AVI |
||||
| BMP to ICO | Tomes Graphical, pp. 359-361 Ignacio Alvarez's UseNet Post with BitmapToIcon function How do I create an icon from a bitmap? (FAQ 2748D) |
||||
| BMP to GIF | TGIFImage from www.melander.dk/delphi/gifimage | ||||
| BMP to JPG |
Converting a BMP to a JPEG and Vice Versa (TI4528D) efg's UseNet Post to convert TJPEGImage to TBitmap, change size of TBitmap, and convert back to TJPEGImage
efg's BMPJPG
Lab Report. Interactively convert BMPs to JPGs or vice versa. Nearly all the JPEG
compession options cn be controlled via the user interface, including image quality and
progressive encoding and display. |
||||
| BMP to TIFF | Save BMP as TIFF 6.0 (D1-D5, updated Sept 2000) http://delphi.icm.edu.pl/ftp/d10free/bmp2tiff.zip http://community.borland.com/homepages/dsp/ftp/d10free/bmp2tiff.zip |
||||
| BMP to TXT | Example of how to convert BMP file to a TXT file of RGB values, and how to convert such a TXT file to RGB values in a TBitmap for display. | ||||
| BMP to WMF | Non-Delphi: AlgoLab Photo Vector turns raster images (.bmp, .jpg, and .png files) into vector images (.wmf files) with a minimum of fuss. www.zdnet.com/downloads/stories/info/0,,001EP8,.html | ||||
| Cursor to Bitmap | Thomas' UseNet Post about how to extract the cursor image from a cursor file for drawing on a bitmap | ||||
| DIBtoBitmap | Procedure in ImageLib Suite DLL. Also see hDIB to TBitmap. | ||||
| hDIB to TBitmap | efg's
Lead Tools-to-Delphi conversions show
two ways to start with a hDIB and end up with a TBitmap. - Method 1. hDIB to TBitmap resulting in bmDDB using StretchDIBits - Method 2. hDIB to TBitmap resulting in bmDIB using MemoryStream |
||||
| ICO to TBitmap | Howard Moon's UseNet Post with ConvertIconToBitmap procedure | ||||
| JPG to BMP | Converting a BMP to JPEG and Vice Versa (TI 4582D) efg's BMPJPG Lab Report (see description above under BMP to JPG) efg's command-line utility for batch conversion of JPGs to BMPs: JPGtoBMP.PAS efg's UseNet Post to convert TJPEGImage to TBitmap, change size of TBitmap, and convert back to TJPEGImage |
||||
| PGM to BMP or JPG | See efg's Interactive PGMP5 "viewer" to display PGM files (P5 format) or the command-line utility ConvertFaces to convert PGM files of the AT&T Laboratories Cambridge Database of Faces (400 images) at www.uk.research.att.com/facedatabase.html to BMP or JPG: PortableGrayMap.ZIP | ||||
| RichEdit to TBitmap | Peter Haas' UseNet Post | ||||
| TControl to TBitmap | efg's example of TControl to TBitmap including a TLabel, TPanel and TBitBtn. | ||||
| TIFF to BMP | TIFF to BMP http://delphi.icm.edu.pl/ftp/d20free/tiff2bmp.zip http://community.borland.com/homepages/dsp/ftp/d20free/tiff2bmp.zip |
||||
| TXT to BMP |
Example of how to convert BMP file to a TXT file
of RGB values, and how to convert such a TXT file to RGB values in a TBitmap
for display.
|
||||
| WMF to BMP | Harm's UseNet Post with example |
Links Verified 7 May 2001
Updated 26 Feb 2005
since 7 May 2001