Solved

Using TJPEGImage from Borland

Posted on 1998-09-30
5
1,968 Views
Last Modified: 2012-05-04
I am using TJPEGImage from Borland (VCL, C++Builder3)

I am having a lot of problems using LoadFromStream. It seems that the Image contents is updated but the image does not get repainted (updated) on the screen !?

Anyone out there that have seen this ?

I will increase the points appropriately if anyone here can help me, otherwise I will try in the Delphi Group ...

I modified their example as follows duplicating my problem :

void __fastcall TForm1::OpenFile(const AnsiString Filename){
        TStream *MyStream;  // Added a stream
      try{
        MyStream = new TFileStream(Filename,fmOpenRead | fmShareDenyNone);  // Use a file stream in stead of LoadFromFile
//            Image1->Picture->LoadFromFile(Filename); // Removed the borland load method
        if (Image1->Picture->Graphic == NULL) { // Create if not existing
// I would also like this built into LoadFromStream on TPicture !
          Image1->Picture->Graphic = new TJPEGImage;

        }
        Image1->Picture->Graphic->LoadFromStream(MyStream);
        delete (TFileStream *)MyStream;
      } catch(EInvalidGraphic &x){
            Image1->Picture->Graphic = NULL;
      }
      SetJPEGOptions(this);
}
0
Comment
Question by:gysbert1
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:WxW
ID: 1174059
I recommend ( although I use Borland too ) to use the K.Nishitas freeware image converter library .
http://einstein.ae.eng.ua.edu/nishita/index.htm

Last time it was shutdown ... if you want I will mail the dll to you . It takes a simple image file and returns a HBITMAP to use.
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1174060
Two things.

1) Is it freeware or will it cost me ?
2) I like the Borland approach to hook into TGraphic. It is the way that images were designed to work and will most likely be the best optimized (display wise). Do I have to Hook into a paint somewhere and do a stretchdraw with that library ? If I do that with the Borland library it works fine but I do not want to go that way if at all possible.


0
 
LVL 6

Expert Comment

by:WxW
ID: 1174061
It is FREE , BUT
the only useful thing is that you read a JPG or other image from a file , and you convert it to a HBITMAP . Also  , you can save a HBITMAP to a JPG file .
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1174062
Ok, I have solved the problem !

I did the unspeakable and changed the Borland code. Their code frees the HBitmap associated with the TJPEGImage when you LoadFromFile. It does not do this whe loading from a stream however. Also, as an optimisation, they do not decompress the JPEG if the bitmap exists, assuming it matches the JPEG data.

I added a line that frees the FBitmap in the TJPEGImage when loading from a stream. The first time that the bitmap is needed it gets created with the new data as it should.

This  looks like a bug on borland's side to me, I will post here if I hear anything from them in future.

WxW, you can have the points for this one. Then you get paid for trying and others can learn from my woes ...

:o(
0
 
LVL 6

Accepted Solution

by:
WxW earned 10 total points
ID: 1174063
Thanks:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

840 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