Solved

JPEG component

Posted on 1998-11-24
15
1,523 Views
Last Modified: 2013-11-19
can someone fix this component ( it doesn't work ).
It's supposed to be like a TImage, but with a JPG in stead of BMP


unit JpegImage;

      interface

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

      type
          TJPGImage = class(TImage)
          private
            FJPGImage : TJpegImage;
            procedure SetJPG(JPG : TJpegImage);
            procedure Paint;override;
            //otherstuff....
           protected
          { Protected declarations }
          public
            constructor Create(AOwner : TComponent);override;
            destructor Destroy;override;
             //stuff
          published
            property JPGImage : TJpegImage read FJPGImage write SetJPG;
            //other stuff////
      end;

      procedure Register;

      implementation

      constructor TJPGImage.Create(AOwner : TComponent);
      begin
        Inherited Create(AOwner);
        FJPGImage := TJpegImage.Create;
        FJPGImage := nil;
      end;

      destructor TJPGImage.Destroy;
      begin
        FJPGImage.Free;
        FJPGImage := nil;
        inherited Destroy;
      end;

      procedure TJPGImage.Paint;
      begin
        Canvas.Draw(0, 0, FJPGImage);
      end;

      procedure TJPGImage.SetJPG(JPG : TJpegImage);
      begin
        FJPGImage := JPG;
        Invalidate;
      end;

      procedure Register;
      begin
        RegisterComponents('Standard', [TJPGImage]);
      end;

      end.
0
Comment
Question by:menorcanet
  • 5
  • 4
  • 3
  • +3
15 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347782
hi menorcanet,

why this in the constructor

      FJPGImage := TJpegImage.Create;
      FJPGImage := nil;

?

It seems you waste some memory

meikl
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347783
I think the reason it doesn't work is pointed out in kretzschmar's comment.

On an aside, you should consider what happens to the old image in SetJPG.
Prehaps it should be freed?

Also, does TJpegImage have a Width or Height property? After creating it in the constructor, do you have a blank 100x100 image, or a 0x0 image?
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1347784
menorcanet

You should also call the inherited call in the paint procedure...

      procedure TJPGImage.Paint;
          begin
           inherited Paint;
            Canvas.Draw(0, 0, FJPGImage);
          end;

Later
BoRiS
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347785
hi menorcanet,
its time for me to place an answer,

Your component cannot work because there is the line

      FJPGImage := nil;

in your constuctor.
Remove this line.

Take a look to the other comments, there are helpful tips.

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347786


hi menorcanet,
Oops, here is the answer,

its time for me to place an answer,

Your component cannot work because there is the line

      FJPGImage := nil;

in your constuctor.
Remove this line.

Take a look to the other comments, there are helpful tips.

meikl
0
 

Author Comment

by:menorcanet
ID: 1347787
kretschmar: if I only change that, I get an acces violation when i drop the component on the form, and a message( canvas doesn't allow drawing ) or something like that.

if I also do what BoRiS says, it seems to work better, I can load the jpg image, but when i try to move or resize the component, it gives an error.

Have you tried the component ?
I use Delphi 3 c/s

I didn't write this code, I don't know much about creating components.


0
 

Author Comment

by:menorcanet
ID: 1347788
hi..
0
 

Expert Comment

by:ItsMe
ID: 1347789
Why don't you use the JPEG Component included in Delphi ? Once
installed your TImage Component is able to read bmp,jpeg,ico ...
0
 

Expert Comment

by:ItsMe
ID: 1347790
You only have to click on "Install new Component" "New library" "Filename of Unit: jpeg"
"Filename of Package: e.g.: jpegs"  Then Delphi will compile jpeg and add it to TImage
Component. You must pay attention to the license agreement of jpeg !
0
 

Author Comment

by:menorcanet
ID: 1347791
where's that component ???
I use Delphi 3 c/s.
Can I use it for comercial programs ?

0
 

Expert Comment

by:ItsMe
ID: 1347792
Hi,
this component is on the Delphi 3 CD. I'm using Delphi 3 Standard so I guess
that you have it, too. Search at DelphiCD\InstallUs\Extras\Jpeg or simply search
your Delphi Directory for JPEG. Try installing it without any path.
Choose:
1. Install new Component
2. In new Package
3. Name of the Unit is "jpeg"
4. Name of the Package "your turn"

I think that you can use it in commercial programs. I'm not sure, you only have to
read the readme.txt. You can also search your Delphi Help for "Jpeg".

regards
ItsMe


0
 

Author Comment

by:menorcanet
ID: 1347793
I get the error "Program or unit'Jpeg.pas' recursively uses itself.

0
 

Expert Comment

by:ItsMe
ID: 1347794
Did you named the new package "jpeg" ? You can give it a name but you are not allowed to name it "jpeg" !
Give the new package the name "jpgcomp" or anything else.

Regards ItsMe

PS: The path of Jpeg on the Delphi CD is: ..\Info\Extras\Jpeg
0
 

Author Comment

by:menorcanet
ID: 1347795
I named it Jpeg2, ( the pas file, the new dpk to create, and the
" unit Jpeg; " inside the jpeg.pas.

and still the same.

Can you send me a component ? if so, please send it in a dpk package.

thanx
0
 

Accepted Solution

by:
anas_madani earned 10 total points
ID: 1347796
Hi  menorcanet

try the following component :

        http:/www.hoerstemeier.com/files/jpgimg.zip

The PASJPEG library, origin for the JPEGImage component:
        http://www.tu-chemnitz.de/~nomssi/pub/pasjpeg.zip

I have download it and it is working so cool .

anas
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

Suggested Solutions

Title # Comments Views Activity
graphic software 6 91
Downloading email attachments 2 79
Corel Draw -- open source replacement ? 8 181
Microsoft Access 97 and Delphi XE2 9 53
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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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":…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

808 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