Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JPEG component

Posted on 1998-11-24
15
Medium Priority
?
1,530 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
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!

 
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 20 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
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…
Suggested Courses

618 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