Solved

JPEG component

Posted on 1998-11-24
15
1,526 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
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…

691 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