Board index » cppbuilder » I want to export a jpeg from a bitmap/TPicture

I want to export a jpeg from a bitmap/TPicture

Sorry for the multiple posts!  I can't seem to get a new post to show up
at the bottom of the list.

I am sorta continuing a previous post that I used but didn't solve my
problem.

I have generated an HBITMAP from a form (snapshot) using some WinAPI
functions.  I can save it as a bitmap, but need it as JPG to output
using my webserver (dynamically).  I installed the borland TJpeg stuff
from
http://www.borland.com/devsupport/bcppbuilder/file_supplements.html.

It contains a good example for displaying jpeg's, but nothing for how to
save them to file or stuff them in an AnsiString.

The problem I am having is that the "dynamic_cast<TJPEGImage
*>(picture->Graphic)" cast returns NULL.  This prevents me from doing
anything using JPEGS.

Does anybody have any suggestions?

What I really need is an AnsiString that contains the jpeg.

Thanks!

 

Re:I want to export a jpeg from a bitmap/TPicture


: Matthew Mello <mmme...@spaceship.com> wrote:

Quote
>Sorry for the multiple posts!  I can't seem to get a new post to show up
>at the bottom of the list.

Well, blame your newsreader ;-)

I have cancelled / deleted the second posting.

--
General information:
  * Post to the right group - http://www.borland.com/newsgroups/
    * Do not cross- or multipost
      * Research at http://www.mers.com/searchsite.html

Stefan Hoffmeister - http://www.econos.de/
(TeamB - http://www.teamb.com/)

Re:I want to export a jpeg from a bitmap/TPicture


Many thanks to Meyer Jean-Francois for this solution!

//---------------------------------------------------------------------
int TphotoDlg::saveToFile(const char * fname)
{
 int stat = 0;
 Graphics::TBitmap *bp = 0;
 TJPEGImage          *jp = 0;
 try{
   //photo->Picture->SaveToFile(fname); // does not work with a jpg
extension filename and an original BITMAP Picture ????
    jp = new TJPEGImage();        // create a new jpeg object
    bp = new Graphics::TBitmap(); // create a new bitmap object
    bp->Assign(Clipboard());   // fill it from the clipboard or from a
bitmap file
    jp->Assign(bp);               // fill the jpeg from the bitmap
    jp->CompressionQuality = 25;  // select compression
   //jp->Performance        = jpBestSpeed;
    jp->Compress();               // compress the image
    jp->SaveToFile(fname);     // save it to filename
    delete bp;
    delete jp;
    stat = 1;
 }catch(...){
   stat = -1;
   if(jp) delete jp;
   if(bp) delete bp;
 }
  return stat;

Quote
}

//---------------------------------------------------------------------
Quote
"Stefan Hoffmeister (TeamB)" wrote:

> : Matthew Mello <mmme...@spaceship.com> wrote:

> >Sorry for the multiple posts!  I can't seem to get a new post to show up
> >at the bottom of the list.

> Well, blame your newsreader ;-)

> I have cancelled / deleted the second posting.

> --
> General information:
>   * Post to the right group - http://www.borland.com/newsgroups/
>     * Do not cross- or multipost
>       * Research at http://www.mers.com/searchsite.html

> Stefan Hoffmeister - http://www.econos.de/
> (TeamB - http://www.teamb.com/)

Other Threads