Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 816
  • Last Modified:

Delphi 3 and GIF/JPEG support in TImage

I am using Delphi 3 Pro.  I am trying to add a JPEG or GIF image to my project's form.  I came across a note somewhere that there is a JPEG.DCU on the installation CD in the \extras folder.  I found the unit, and placed it in the Delphi \bin folder, and added JPEG to my "uses" line, however, whenever I place a TImage on my form, and double click on the component, the Picture Editor dialog does not list "JPEG" as a supported file type.

How do you add a JPEG image to a Delphi 3 form?

Likewise, a GIF?
0
Kapusta
Asked:
Kapusta
  • 4
1 Solution
 
tongaliteCommented:
Hi,
To load Gifs you'll need to install a Gif control. One of the best is from Sulako (do a Google search or leave an e-mail address and I'll mail you the comp. I use only that comp in D3 Pro)

To load a JPEG image do this:
***************
procedure TForm1.Button1Click(Sender: TObject);

var
    jpg: TJPEGImage; // TJPEGImage object to load my jpeg into
begin
    jpg := TJPEGImage.Create;
    jpg.LoadFromFile('C:\Windows\Desktop\race.jpg');  
//Adjust the path to your Jpeg image

    Image1.Picture.Assign(jpg); // Now assign the jpeg to the TImage's

    jpg.Free;  // TJPEGImage object has outlived its usefulness

end;
*****************
hope this helps :-)
Good luck
T.

0
 
tongaliteCommented:
Forgot to mention...

JPEG in USES clause.
T.
0
 
KapustaAuthor Commented:
>> JPEG in USES clause.

But that does not change the "File type" filter list for the Picture Editor when you double click on a TImage component.  JPEGs aren't permitted to be loaded via this method (Picture Editor).
0
 
tongaliteCommented:
Hi,
That's correct you cannot load them with the picture editor. You must load them from file. Alternatively you can compile the jpeg image into a resource file and stream the image from the resource file. This means the image is embedded into your exe and so therefore no dependance on any external files.

T.
0
 
tongaliteCommented:
Why don't you use an OpenPictureDialog?
You can set the filter to open jpegs in the filter editor. Add this in the editor:
//in the left column type  =      JPEG (*.jpg)
//in the right column type =     *.jpg

here is a sample unit to display the images;
//add a Timage. a Tbutton and TOpenPictureDialog (pd1)

*******************
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, ExtCtrls,Jpeg,ExtDlgs;
type
  TForm1 = class(TForm)
    pd1: TOpenPictureDialog;
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);

begin

 if PD1.Execute then
begin
// Load the selected image
   Image1.Picture.LoadFromFile(
                  pd1.FileName );

   end;
    end;
     end.
**************************
That's about all I can suggest.
T.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now