Solved

JPEG component

Posted on 1998-11-24
15
1,517 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now