hi here!
I am trying to access files that are stored as Jpeg files, is there an easy way to display these image files without performance loss ?
hi here!
I am trying to access files that are stored as Jpeg files, is there an easy way to display these image files without performance loss ?
You can load the JPeg file using an instance of TJPEGImage and then assign it to a TBitmap to display. You find TJPEGImage in unit jpeg.
jpeg := TJPEGImage.Create;
jpeg.LoadFromFile('filename.jpg');
bitm := TBitmap.Create;
bitm.Assign(jpeg);
Image1.Height := bitm.Height;
Image1.Width := bitm.Width;
Image1.Canvas.Draw(0, 0, bitm);
Alternatively, this should also work:
bitm := TBitmap.Create;
bitm.Assign('filename.jpg');
Image1.Height := bitm.Height;
Image1.Width := bitm.Width;
Image1.Canvas.Draw(0, 0, bitm);
I dont believe D7 can handle CMYK JPEG's.
If you cant open it using the JPEG unit as Ralph posted, you might consider using something like GDI+ to load the graphic file.
Actually, I once modified Jpeg.pas unit to partial CMYK support. Basically after
jpeg_start_decompress(jc.d)
you should check
if jc.d.out_color_space = JCS_CMYK then
and if true following jpeg_read_scanlines will get 4 bytes data instead of 3 bytes.
Also cinfo.saw_Adobe_marker indicates inverted values (probably Adobe was first who introduced CMYK jpeg variation).
But the most difficult part is CMYK-RGB conversion. Since there's no universal formula, in best systems it's always table approach. I tried to find some simple approximation, but there's always a picture that does not fit. Just as an example, don't use this formulas as a reference:
R_:=Max(254 - (111*C + 2*M + 7*Y + 36*K) div 128, 0);
G_:=Max(254 - (30*C + 87*M + 15*Y + 30*K) div 128, 0);
B_:=Max(254 - (15*C + 44*M + 80*Y + 24*K) div 128, 0);