Board index » cppbuilder » Getting JPEG images from a BLOB field

Getting JPEG images from a BLOB field

I am trying to retrieve JPEG images from a database.  The DBImage
component evidently only works with bitmaps.  Whats the best approach to
this problem?  Also loading a JPEG to a TImage at design time works fine
but doing a TImage->Picture->LoadFromFile() at runtime with the error
".jpg format invalid".  Help please?

Bill Wentworth

 

Re:Getting JPEG images from a BLOB field


The TPicture i do beleve has a Registerformat function where is you can set
the Tpicture type to a TJPEGimage..
  but if you can not figured that one out then you could try the DRaw, i
know this works with TJPEG's
Image->Canvas->Draw(0,0, MyJpeg);
Quote
Bill Wentworth wrote:
> I am trying to retrieve JPEG images from a database.  The DBImage
> component evidently only works with bitmaps.  Whats the best approach to
> this problem?  Also loading a JPEG to a TImage at design time works fine
> but doing a TImage->Picture->LoadFromFile() at runtime with the error
> ".jpg format invalid".  Help please?

> Bill Wentworth

Re:Getting JPEG images from a BLOB field


Quote
> I am trying to retrieve JPEG images from a database.  The DBImage
> component evidently only works with bitmaps.  Whats the best approach to

It's a real pain to work with, but I think there are 2 options:

1] Don't use the DBImage component. I've found it to be a real resource hog,
and I think it leaks more than a Pentagon spy ring. I've been having a real
fight with it and am beginning to make the transition over to doing it all
myself using TImages.

2] Check to see if you've loaded a JPEG and then assign it to a TBitmap and
Assign that to the DBImage. I don't think there's an easy way to turn a JPEG
into a TBitmap for DBImage to take. Here's some code I use to do this:

        TJPEGImage* jpg = dynamic_cast<TJPEGImage*>(image->Graphic);
        Graphics::TBitmap* bmp=0;
        if ( jpg )
        { // turn jpg into bmp for db storage
            try
            {
                bmp = new Graphics::TBitmap();
                bmp->Assign(pd->image->Graphic);
            }
            catch(...)
            {
            }
        }
        else
        { // just use images bitmap
            bmp = pd->image->Bitmap;
        }

        data->TblPhoto->Assign(bmp);
        delete bmp;

Quote
> this problem?  Also loading a JPEG to a TImage at design time works fine
> but doing a TImage->Picture->LoadFromFile() at runtime with the error
> ".jpg format invalid".  Help please?

Be sure you have the #incluede "jpeg.hpp" at the top of the file and that
you've done a build all. It can be a weird and unpredictable process as to
when LoadFromFile figures out it can load JPEGs, but it will work.

+===================================================+
| Jonathan Arnold (mailto:jdarn...@buddydog.org)    |
| http://www.buddydog.org                           |
+===================================================+

Grossman's Law: Complex problems have answers that are
easy to discover and understand, but wrong.

Re:Getting JPEG images from a BLOB field


On Mon, 25 Oct 1999 07:45:16 -0400, Jonathan Arnold

Quote
<jdarn...@buddydog.org> wrote:
>1] Don't use the DBImage component. I've found it to be a real resource hog,
>and I think it leaks more than a Pentagon spy ring. I've been having a real
>fight with it and am beginning to make the transition over to doing it all
>myself using TImages.

TBlobField itself leaks.
www.totalqa.com/support/leaksd4.html

Gerard

Other Threads