Solved

Using TJPEGImage from Borland

Posted on 1998-09-30
5
1,937 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

743 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