Главная страница | назад





Article #15996: Displaying a 24 bit True Color bitmap image on a 256 color display

 Question and Answer Database
FAQ996D.txt Displaying a 24 bit True Color bitmap image on a 256 color display
Category :VCL
Platform :All
Product :All 32 bit
Question:
How can I display a 24 bit True Color bitmap image on a 256 color
Display under Delphi 3?
Answer:
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 TForm1.Button1Click(Sender: TObject);
var
JP : TJPEGImage;
IM : TImage;
TempFileName : string;
begin
{Pop up a Open Dialog}
OpenDialog1.Options := [ofNoChangeDir, ofFileMustExist];
OpenDialog1.Filter := 'Bitmap Files (*.bmp)|*.bmp';
if OpenDialog1.Execute then begin
{Create a temporary TImage}
IM := TImage.Create(nil);
{Load the bitmap file}
IM.Picture.LoadFromFile(OpenDialog1.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}
Image1.Picture.LoadFromFile(TempFileName);
{Delete the temp file}
DeleteFile(TempFileName);
end;
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99