Solved

Using TJPEGImage from Borland

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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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