riccohb
asked on
JPG/GIF images
I'm sure this question is a piece of cake, but I can't seem to find any information on it anywhere.
I want to display jpg and gif images within an application, but TImage only seems to be able to handle bitmaps. What do I use to display jpgs and gifs?
I want to display jpg and gif images within an application, but TImage only seems to be able to handle bitmaps. What do I use to display jpgs and gifs?
ASKER
Thanks for getting back to me.
I've added JPEG to the uses clause of the unit, but I get an EInvalidGraphic error 'Unknown picture file extension (.jpg)' when the code gets to the line
imgPics.Picture.LoadFromFi le(lbxPics .Items[i]) ;
where imgPics is TImage and lbxPics is a list box. When the user double clicks an item in the list box the code iterates through the list box items and tries to load the one corresponding to ItemIndex i.
I've added JPEG to the uses clause of the unit, but I get an EInvalidGraphic error 'Unknown picture file extension (.jpg)' when the code gets to the line
imgPics.Picture.LoadFromFi
where imgPics is TImage and lbxPics is a list box. When the user double clicks an item in the list box the code iterates through the list box items and tries to load the one corresponding to ItemIndex i.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
uses jpeg;
var
JPegImage : TJpegImage;
begin
JPegImage := TJPegImage.Create;
JPegImage.LoadFromFile(lbx Pics.Items [i]);
imgPics.Picture.Assign(JPe gImage);
JPegImage.Free;
end;
Regards, Geo
uses jpeg;
var
JPegImage : TJpegImage;
begin
JPegImage := TJPegImage.Create;
JPegImage.LoadFromFile(lbx
imgPics.Picture.Assign(JPe
JPegImage.Free;
end;
Regards, Geo
yep, geo,
this is a workaround,
but atleast it should be enough to add the jpeg-unit
into the uses calause, as the jpeg-unit registers itself
to the supported graphicformats
maybe riccohb did not a full rebuild of the app
meikl ;-)
this is a workaround,
but atleast it should be enough to add the jpeg-unit
into the uses calause, as the jpeg-unit registers itself
to the supported graphicformats
maybe riccohb did not a full rebuild of the app
meikl ;-)
You are right, meikl. It should be. Perhaps it's a Delphi version problem.
mmm, i would also, as kretzchmer sugested "graphicEx from mike lischke" not only is that a quality piece of software, but it lets you do neat stuff with many other file formats, including ONG's which, for almost everything are much nicer then GIF's ;p
GL
Mike
GL
Mike
Hello
For jpegs just add jpeg.pas to your uses and use the following statement to register the JPG format for a TImage.
Image1.Picture.RegisterFil eFormat('J PG','JPEG Bitmap',TJPEGIMAGE);
After you do this, you can load the image from a stream or file.
One Bad thing about gif's ,you have to pay royalties to unisys for reading and/or writing gifs,read here :
http://216.239.39.100/search?q=cache:V56QJZeuPAMC:www.unisys.com/unisys/lzw/+unisys&hl=en
I rather perfer PNG,
here's where to get component free with source:
http://pngdelphi.sourceforge.net/download.php?goto=pngimage142.zip&file=pngimage.txt
read the help file for instructions to install and use
Good luck!
For jpegs just add jpeg.pas to your uses and use the following statement to register the JPG format for a TImage.
Image1.Picture.RegisterFil
After you do this, you can load the image from a stream or file.
One Bad thing about gif's ,you have to pay royalties to unisys for reading and/or writing gifs,read here :
http://216.239.39.100/search?q=cache:V56QJZeuPAMC:www.unisys.com/unisys/lzw/+unisys&hl=en
I rather perfer PNG,
here's where to get component free with source:
http://pngdelphi.sourceforge.net/download.php?goto=pngimage142.zip&file=pngimage.txt
read the help file for instructions to install and use
Good luck!
a sample, with graphicEx
Function TForm1.DisplayImage(AStrea m : TStream; AExtension : String) : Boolean;
Var
//Extended Graphicformats
AExGraphicClass: TGraphicExGraphicClass;
AExGraphic: TGraphicExGraphic;
//Standard Graphicformats
AGraphicClass : TGraphicClass;
AGraphic : TGraphic;
OldPosition : Integer;
begin
Result := False; //do as that cannot be loaded
If Assigned(AStream) then
try
OldPosition := AStream.Position;
try
AStream.Position := 0; //Remember Streams Position
//Check for Extended Graphicformats
AExGraphicClass := GraphicEx.FileFormatList.G raphicFrom Content(AS tream);
if AExGraphicClass <> Nil then
begin
AExGraphic := AExGraphicClass.Create;
try
//Load Extended Graphicformats
AExGraphic.LoadFromStream( AStream);
Image1.Picture.Graphic := AExGraphic;
Result := True;
finally
AExGraphic.Free;
end;
end
else
begin
//Check for Standard Graphicformats
AGraphicClass := GraphicEx.FileFormatList.G raphicFrom Extension( AExtension );
if AGraphicClass <> Nil then
begin
AGraphic := AGraphicClass.Create;
try
//Load Standard Graphicformats
AGraphic.LoadFromStream(AS tream);
Image1.Picture.Graphic := AGraphic;
Result := True;
finally
AGraphic.Free;
end;
end;
end;
finally
AStream.Position := OldPosition;
end;
except
Raise;
end;
end;
meikl ;-)
Function TForm1.DisplayImage(AStrea
Var
//Extended Graphicformats
AExGraphicClass: TGraphicExGraphicClass;
AExGraphic: TGraphicExGraphic;
//Standard Graphicformats
AGraphicClass : TGraphicClass;
AGraphic : TGraphic;
OldPosition : Integer;
begin
Result := False; //do as that cannot be loaded
If Assigned(AStream) then
try
OldPosition := AStream.Position;
try
AStream.Position := 0; //Remember Streams Position
//Check for Extended Graphicformats
AExGraphicClass := GraphicEx.FileFormatList.G
if AExGraphicClass <> Nil then
begin
AExGraphic := AExGraphicClass.Create;
try
//Load Extended Graphicformats
AExGraphic.LoadFromStream(
Image1.Picture.Graphic := AExGraphic;
Result := True;
finally
AExGraphic.Free;
end;
end
else
begin
//Check for Standard Graphicformats
AGraphicClass := GraphicEx.FileFormatList.G
if AGraphicClass <> Nil then
begin
AGraphic := AGraphicClass.Create;
try
//Load Standard Graphicformats
AGraphic.LoadFromStream(AS
Image1.Picture.Graphic := AGraphic;
Result := True;
finally
AGraphic.Free;
end;
end;
end;
finally
AStream.Position := OldPosition;
end;
except
Raise;
end;
end;
meikl ;-)
about graphicEx
http://www.delphi-gems.com/Graphics.html
(free for nonComercial use)
additional supported grafikformats
(just taken from the site)
TIFF images (*.tif; *.tiff), extended base line implementation
- 1..16 bits per sample
- indexed, grayscale, RGB(A), CMYK, L*a*b*
- uncompressed, packed bits, LZW, CCITT T.4, Thunderscan, Deflate, new style JPEG
GFI fax images (*.fax), uses TTIFFGraphic to read
SGI images (*.bw, *.rgb, *.rgba, *.sgi)
- 1..16 bits per sample
- indexed, grayscale, RGB(A)
- uncompressed, RLE
Autodesk images files (*.cel; *.pic) old style only
- 8 bits per sample, indexed and uncompressed
Truevision images (*.tga; *.vst; *.icb; *.vda; *.win), write support included
- 5 and 8 bits per sample
- grayscale, indexed, 15 bits RGB (555), 24 bits RGB(A)(888)
- uncompressed, RLE
ZSoft Paintbrush images (*.pcx, *.pcc; *.scr)
- 1..8 bits per sample
- grayscale, indexed, RGB
- uncompressed, RLE
Kodak Photo-CD images (*.pcd)
- 8 bits per sample in YCbCr in any resolution (192 x 128 up to 6144 x 4096)
- Portable pixel/gray map images (*.ppm, *.pgm, *.pbm)
- 1 and 8 bits per sample
- grayscale, indexed, RGB uncompressed
Dr. Halo images (*.cut, *.pal)
- 8 bits per sample indexed, RLE compressed
CompuServe images (*.gif)
- 1, 4, 8 bits per sample indexed, LZW compressed
SGI Alias/Wavefront images (*.rla, *.rpf)
- 8 bits per sample RGB(A), RLE compressed
Standard Windows bitmap images (*.bmp, *.rle, *.dib)
Photoshop images (*.psd, *.pdd)
- 1, 8, 16 bits per sample
- indexed, RGB, CMYK, CIE L*a*b*
- uncompressed and packed bits
Paintshop Pro images (*.psp)
- 1, 4, 8 bits per sample
- indexed, grayscale, RGB
- uncompressed, RLE and LZ77
- single-layered files only!
Portable network graphic images (*.png)
- 1, 2, 4, 8, 16 bits per sample
- indexed, grayscale alpha, RGB(A), LZ77 compressd
http://www.delphi-gems.com/Graphics.html
(free for nonComercial use)
additional supported grafikformats
(just taken from the site)
TIFF images (*.tif; *.tiff), extended base line implementation
- 1..16 bits per sample
- indexed, grayscale, RGB(A), CMYK, L*a*b*
- uncompressed, packed bits, LZW, CCITT T.4, Thunderscan, Deflate, new style JPEG
GFI fax images (*.fax), uses TTIFFGraphic to read
SGI images (*.bw, *.rgb, *.rgba, *.sgi)
- 1..16 bits per sample
- indexed, grayscale, RGB(A)
- uncompressed, RLE
Autodesk images files (*.cel; *.pic) old style only
- 8 bits per sample, indexed and uncompressed
Truevision images (*.tga; *.vst; *.icb; *.vda; *.win), write support included
- 5 and 8 bits per sample
- grayscale, indexed, 15 bits RGB (555), 24 bits RGB(A)(888)
- uncompressed, RLE
ZSoft Paintbrush images (*.pcx, *.pcc; *.scr)
- 1..8 bits per sample
- grayscale, indexed, RGB
- uncompressed, RLE
Kodak Photo-CD images (*.pcd)
- 8 bits per sample in YCbCr in any resolution (192 x 128 up to 6144 x 4096)
- Portable pixel/gray map images (*.ppm, *.pgm, *.pbm)
- 1 and 8 bits per sample
- grayscale, indexed, RGB uncompressed
Dr. Halo images (*.cut, *.pal)
- 8 bits per sample indexed, RLE compressed
CompuServe images (*.gif)
- 1, 4, 8 bits per sample indexed, LZW compressed
SGI Alias/Wavefront images (*.rla, *.rpf)
- 8 bits per sample RGB(A), RLE compressed
Standard Windows bitmap images (*.bmp, *.rle, *.dib)
Photoshop images (*.psd, *.pdd)
- 1, 8, 16 bits per sample
- indexed, RGB, CMYK, CIE L*a*b*
- uncompressed and packed bits
Paintshop Pro images (*.psp)
- 1, 4, 8 bits per sample
- indexed, grayscale, RGB
- uncompressed, RLE and LZ77
- single-layered files only!
Portable network graphic images (*.png)
- 1, 2, 4, 8, 16 bits per sample
- indexed, grayscale alpha, RGB(A), LZ77 compressd
ASKER
Thank you.
:-(
;-) saw you posted a q for me
:-( -> :-)
:-( -> :-)
get graphicEx from mike lischke
links may follow
jpg, should be no problem,
just add the unit jpeg into the uses-clause
meikl ;-)