Solved

Displaying Jpeg images in a form

Posted on 1998-11-22
3
300 Views
Last Modified: 2013-11-19
Good day all,

Could someone put up a code fragment for grabbing and displaying a jpeg on a form? The reference to where the file is could be a field in a database, or a BLOB. (Well, actually, those are the same things.) I'm pretty much just looking to display some jpegs on a form, though.

I'll be poking around Tjpeg this evening...

Oneeye
0
Comment
Question by:oneeye
3 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1347620
Place a TJPEGImage component on your form. Put a jpeg image in it like this:

MyJPEGImage.LoadFromFile('MyJpeg.jpg');

or

MyJPEGImage.LoadFromStream(TFileStream.Create('MyJPEG.jpg', rmOpenRead)).

The latter one can be used with a TMemoryStream if you want to read the JPEG out of a BLOB...

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1347621
I don't have that component... I have Delphi 3 and use this:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,JPEG;

type
  TForm1 = class(TForm)
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}



procedure TForm1.FormClick(Sender: TObject);
var JPG: TjpegImage;
begin
if FileExists('c:\a.jpg') then begin
    JPG := TJpegImage.Create;
    try
      JPG.LoadFromFile('c:\a.jpg');
      Canvas.Draw(0,0, JPG);
    finally
      JPG.Free;
    end;
end;
end;

end.




try this, ( you have to double click on the OnClick event of the form on the object inspector ).

then run it, click on the form, and there you have it !


bryan


0
 

Author Comment

by:oneeye
ID: 1347622
Ah, thanks both of you. In combination with the example in the delphi help, that gives me a pretty good handle on it...

Oneeye
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this tutorial viewers will learn how to create blended and gradiated shapes in Illustrator using the blend tool Draw two shapes, one of them in a different color: Select both and create a blend by going to Object > Blend > Make: Blends can also b…
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…

713 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