Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JPG/GIF images

Posted on 2002-06-18
13
904 Views
Last Modified: 2013-11-19
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?
0
Comment
Question by:riccohb
  • 6
  • 2
  • 2
  • +3
13 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7086396
get the gifimage-component from melander or
get graphicEx from mike lischke

links may follow


jpg, should be no problem,
just add the unit jpeg into the uses-clause

meikl ;-)
0
 

Author Comment

by:riccohb
ID: 7086687
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.LoadFromFile(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.
0
 
LVL 8

Accepted Solution

by:
Cesario earned 50 total points
ID: 7086701
Hi riccohb,

Meikl is right :-))

TImage support JPEG-Format. Just add the JPEG unit to you Form.

Uses Windows,.......,JPEG,Gifimage;


you can download the TGIFImage v.2.2 Componentn form Torry:
http://www.torry.net/vcl/graphics/gif/gifimage.exe

Best Regards

Cesario
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 17

Expert Comment

by:geobul
ID: 7087592
Hi,

uses jpeg;

var
  JPegImage : TJpegImage;
begin
  JPegImage := TJPegImage.Create;
  JPegImage.LoadFromFile(lbxPics.Items[i]);
  imgPics.Picture.Assign(JPegImage);
  JPegImage.Free;
end;

Regards, Geo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7087633
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 ;-)
0
 
LVL 17

Expert Comment

by:geobul
ID: 7087730
You are right, meikl. It should be. Perhaps it's a Delphi version problem.
0
 
LVL 6

Expert Comment

by:edey
ID: 7089934
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
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 7090335
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.RegisterFileFormat('JPG','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!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7091731
a sample, with graphicEx


Function TForm1.DisplayImage(AStream : 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.GraphicFromContent(AStream);
      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.GraphicFromExtension(AExtension);
        if AGraphicClass <> Nil then
        begin
          AGraphic := AGraphicClass.Create;
          try
            //Load Standard Graphicformats
            AGraphic.LoadFromStream(AStream);
            Image1.Picture.Graphic := AGraphic;
            Result := True;
          finally
            AGraphic.Free;
          end;
        end;
      end;
    finally
      AStream.Position := OldPosition;
    end;
  except
    Raise;
  end;
end;

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7092003
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
0
 

Author Comment

by:riccohb
ID: 7092077
Thank you.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7092081
:-(
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7092105
;-) saw you posted a q for me
:-( -> :-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question