Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2056
  • Last Modified:

Using TJPEGImage from Borland

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
gysbert1
Asked:
gysbert1
  • 3
  • 2
1 Solution
 
WxWCommented:
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
 
gysbert1Author Commented:
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
 
WxWCommented:
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
 
gysbert1Author Commented:
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
 
WxWCommented:
Thanks:)
0

Featured Post

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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now