From: "Earl F. Glynn" Subject: Re: 8 bit BMP to 8 bit JPEG Date: 21 Jan 2000 00:00:00 GMT Newsgroups: borland.public.delphi.graphics "Bob Villiers" <100522.66@COMPUSERVE.COM> wrote in message news:VA.00000163.01476379@cisppp... > Could someone please show me how to convert a 8 bit bitmap to a 8 bit > JPeg. I can convert to 24 bit ok but not 8bit. The online documentation for TJPEGImage says: "Use PixelFormat to set the pixel format of the JPEG image to 8-bit for video drivers that cannot display 24-bit. The native format of a JPEG image is 24-bit. PixelFormat is used for decompression, that is, for reading files. PixelFormat will also apply to a bitmap if the image is copied to it." I took a look at the JPEG.PAS source and the PixelFormat defaults to the video mode. There is once section of code that sets jc.d.quantize_color := TRUE; jc.d.desired_number_of_colors = 236; if PixelFormat is jf8bit or jc.d.out-color_space = JCS_GRAYSCALE, which would make sense for 256-color display mode (Windows reserves 20 of the colors). In TJPEGImage.GetMap, the FBitmap.PixelFormat is set to pf8bit when the JPEG's Pixelformat is jf8bit (or out_color_space is JCS_Grayscale). So in several quick tests I could not detect any change in a JPEG converted from a BMP. An 8 bit BMP creates the same JPEG regardless of the JPEG's PixelFormat setting. Likewise for a 24 bit BMP in creating a JPEG. BUT, I could detect some difference while reading a JPEG and creating a BMP. Consider the following: procedure TForm1.Button2Click(Sender: TObject); VAR Bitmap: TBitmap; JPEG: TJPEGImage; begin JPEG := TJPEGImage.Create; TRY JPEG.PixelFormat := jf8bit; JPEG.LoadFromFile('Fireworks.JPG'); Bitmap := TBitmap.Create; TRY Bitmap.Assign(JPEG); Bitmap.SaveToFile('Fireworks.BMP'); Image1.Picture.Graphic := Bitmap FINALLY Bitmap.Free; END; FINALLY JPEG.Free END end; The code above will result in a pf8bit Fireworks.BMP because the JPEG.PixelFormat = jf8bit. This code will work in either high color or true color since palettes are handled well. BUT, if you set JPEG.PixelFormat := jf24bit, while in 256 color mode, the above code will create a 24-bits/pixel bitmap, which will not have the correct palette, and will not display quite right. So, I don't think the JPEG.PixelFormat buys you very much. -- efg Earl F. Glynn Overland Park, KS USA efg's Computer Lab: http://www.efg2.com/Lab