| |
| Displaying a 24 bit True Color bitmap image on a 256 color display |
 |
How can I display a 24 bit True Color bitmap image on a 256 color Display under Delphi 3?
You can take advantage of the new graphics capabilities of the TBimap and TJpegImage components of Delphi 3. When Delphi 3 loads a bitmap image, it keeps a copy of the device independent bitmap image it loads from a file in the background. The TJPEGImage component is very good at color reducing a full color image down to 256 colors. By Loading the bitmap, then assigning the image to a Jpeg and saving it to a temporary ".JPG" file, you can then load the temporary file back into a TImage with much better results than simply loading the bitmap file unconverted. The following example demonstrates the necessary steps to achieve these results.
Example:
uses JPEG;
procedure TForm .Button Click(Sender: TObject);
var
JP : TJPEGImage;
IM : TImage;
TempFileName : string;
begin
{Pop up a Open Dialog}
OpenDialog .Options := [ofNoChangeDir, ofFileMustExist];
OpenDialog .Filter := 'Bitmap Files (*.bmp)|*.bmp';
if OpenDialog .Execute then begin
{Create a temporary TImage}
IM := TImage.Create(nil);
{Load the bitmap file}
IM.Picture.LoadFromFile(OpenDialog .FileName);
{Create a temporary TJPEGImage}
JP := TJPEGImage.Create;
{Priorty on quality}
JP.Performance := jpBestQuality;
{Assign the bitmap to the JPEG}
JP.Assign(IM.Picture.Graphic);
{Free the temp image}
IM.Free;
{Make a temp file name with the extension of .jpg}
TempFileName := 'test.jpg';
{Save the JPEG to a temp file}
JP.SaveToFile(TempFileName);
{Free the JPEG}
JP.Free;
{Load the temp file to an image on the form}
Image .Picture.LoadFromFile(TempFileName);
{Delete the temp file}
DeleteFile(TempFileName);
end;
end;
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|