Solved

JPEG component

Posted on 1998-11-24
15
1,515 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility


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
Comment Utility
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
Comment Utility
hi..
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Expert Comment

by:ItsMe
Comment Utility
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
Comment Utility
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
Comment Utility
where's that component ???
I use Delphi 3 c/s.
Can I use it for comercial programs ?

0
 

Expert Comment

by:ItsMe
Comment Utility
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
Comment Utility
I get the error "Program or unit'Jpeg.pas' recursively uses itself.

0
 

Expert Comment

by:ItsMe
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
I've been using this technique since Adobe CS2, and it should work with any version of Illustrator that includes the appearance panel. In this tutorial we'll create a button using the appearance panel in Adobe Illustrator, and then save it as a r…
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…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now