views:

208

answers:

3

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 ?

+1  A: 

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);
Ralph Rickenbach
Just include the jpeg unit in your uses so the unit registers itself and then use `Image1.Picture.LoadFromFile('c:\filename.jpg');`. Image1 is a TImage placed on your form.
The_Fox
TJPEGImage cannot handle CMYK JPEG Images, You might want to get something like NativeJPEG.
Ritsaert Hornstra
There is something called "AutoCMYKToRGB" does anyone know how this works ?
Plastkort
Perhaps this one is the solution.. I use Delphi 7 today, but one day I plan to upgrade, http://cc.embarcadero.com/item/19723 however it has the jpegex unit which I tried before but was very slow, but this version might be modified, I will give it a go
Plastkort
+1  A: 

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.

GrandmasterB
+1  A: 

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);
Maksee