Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to display a jpeg into a TDBImage component

791 views
Skip to first unread message

Maurizio Seghi

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
I'm writing a database app. that need to load jpeg file and save it to a
BLOB binary field...
The problem is that the DBImage->Picture->LoadFromFile function read the
file correctly but the component do not display the image...
If I try to do the same thing with a TImage component it show the image
correctly...

Note: After several try I note that only .bmp image file are displayed by
the TDBImage component...

Anyone have and idea to solve this problem?

Thanks in advance...

Damon Chander

unread,
Dec 21, 1999, 3:00:00 AM12/21/99
to
Hi Maurizio,

> I'm writing a database app. that need to load jpeg file and save it to a
> BLOB binary field...
> The problem is that the DBImage->Picture->LoadFromFile function read the
> file correctly but the component do not display the image...
> If I try to do the same thing with a TImage component it show the image
> correctly...

It is possible that the TDBImage component was not designed to handle
JPEG images. You should confirm this with the .database.desktop
newsgroup. Perhaps your design is flexible enough to go through an
intermediate bitmap? That is, load the JPEG, create a temporary
TBitmap, then assign the Bitmap to the DBImage.

Good luck!

Damon C.

Frank Markus S.

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
I´m working on a similar task. It works allright for me (I use a TImage and
TJpegImage inbetween).
Well, allright... Not really... I still have to find out why it sometimes
locks complete datastreams in a database, but that´s it!

What about that cppbuilder.database newsgroup ???


regards...

--
Frank Markus Schanzenbächer
Programmer & Designer 4
visual and audial medias
Germany @ Individual Software GmbH
Mailto:Frank_...@inso-gmbh.de

Check: http://signpro.iscool.net for a Win32/CBuilder !Open Source!
Project

Maurizio Seghi schrieb in Nachricht <83ni3l$bm...@forums.borland.com>...


>I'm writing a database app. that need to load jpeg file and save it to a
>BLOB binary field...
>The problem is that the DBImage->Picture->LoadFromFile function read the
>file correctly but the component do not display the image...
>If I try to do the same thing with a TImage component it show the image
>correctly...
>

gerard patel

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to
On Tue, 21 Dec 1999 21:53:42 -0500, Damon Chander <dm...@cornell.edu>
wrote:

>It is possible that the TDBImage component was not designed to handle
>JPEG images.

Yes, indeed. This is a frequently asked question in the
database newsgroups :-)

Gerard

Frank Markus S.

unread,
Dec 22, 1999, 3:00:00 AM12/22/99
to

gerard patel

unread,
Dec 23, 1999, 3:00:00 AM12/23/99
to
On Wed, 22 Dec 1999 08:19:20 +0100, "Frank Markus S."
<Frank_...@t-online.de> wrote:

>I´m working on a similar task. It works allright for me (I use a TImage and
>TJpegImage inbetween).
>Well, allright... Not really... I still have to find out why it sometimes
>locks complete datastreams in a database, but that´s it!
>

AFAIR there is a known leakage in the vcl database
and a known issue in the order of closing blob and
posting, but other than that I have not heard much
about problems. Of course with database there are
always specific cases :-/

>What about that cppbuilder.database newsgroup ???
>

it's probably
borland.public.cppbuilder.database.desktop.

Gerard

Anders Melander

unread,
Dec 24, 1999, 3:00:00 AM12/24/99
to
"Maurizio Seghi" <p...@zen.it> wrote:

>I'm writing a database app. that need to load jpeg file and save it to a
>BLOB binary field...

If you can read Pascal, you can find a demo of how to accomplish this
with a TImage component here:

http://www.melander.dk/delphi/gifimage/#Download

The demo uses file signatures to determine the type of the image
stored in the BLOB.

DIXI

+--------------------from usenet----------------------+
| Anders Bo Melander | mailto:and...@melander.dk |
| Denmark | http://www.melander.dk |
+------------------------+----------------------------+

Kevin Berry

unread,
Dec 24, 1999, 3:00:00 AM12/24/99
to
Here's how to both load different file formats and retrieve them from
database BLOB fields using a TDBImage component.

First you have to register the JPEG format:

#include <jpeg.hpp>

//register JPEG class
DBImage1->Picture->RegisterFileFormat(__classid(TJPEGImage), "jpg",
"JPEG File", __classid(TJPEGImage));


To load bmp, emf, ico, jpg images into the database:

if (OpenDialog1->Execute())
{
Image1->Picture->LoadFromFile(OpenDialog1->FileName);
Table1->Edit();
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");
field->LoadFromFile(OpenDialog1->FileName);
Table1->Post();
}


To retrieve images you should set your DBImage1 control's AutoDisplay
property to false. Then do one of the following based on the image type in
the database:

//do for jpeg
TBlobField* field = (TBlobField*)Table1->FieldByName("OVERLAY");
TBlobStream* stream = new TBlobStream(field, bmRead);
TJPEGImage* image = new TJPEGImage;
DBImage1->Picture->Assign(image);
DBImage1->Picture->Graphic->LoadFromStream(stream);
delete image;

//do for metafile
TBlobField* field = (TBlobField*)Table1->FieldByName("OVERLAY");
TBlobStream* stream = new TBlobStream(field, bmRead);
Image1->Picture->Metafile->LoadFromStream(stream);

//do for icon
TBlobField* field = (TBlobField*)Table1->FieldByName("OVERLAY");
TBlobStream* stream = new TBlobStream(field, bmRead);
Image1->Picture->Icon->LoadFromStream(stream);

//do for bitmap
DBImage1->LoadPicture();

Kevin Berry
kevin...@earthlink.net

Maurizio Seghi wrote in message <83ni3l$bm...@forums.borland.com>...


>I'm writing a database app. that need to load jpeg file and save it to a
>BLOB binary field...

Kevin Berry

unread,
Dec 24, 1999, 3:00:00 AM12/24/99
to

Here's how to both load different file formats and retrieve them from
database BLOB fields using a TDBImage component.

First you have to register the JPEG format:

#include <jpeg.hpp>

//register JPEG class
DBImage1->Picture->RegisterFileFormat(__classid(TJPEGImage), "jpg",
"JPEG File", __classid(TJPEGImage));


To load bmp, emf, ico, jpg images into the database:

if (OpenDialog1->Execute())
{


Table1->Edit();
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");
field->LoadFromFile(OpenDialog1->FileName);
Table1->Post();
}


To retrieve images you should set your DBImage1 control's AutoDisplay
property to false. Then do one of the following based on the image type in
the database:

//do for jpeg
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");


TBlobStream* stream = new TBlobStream(field, bmRead);
TJPEGImage* image = new TJPEGImage;
DBImage1->Picture->Assign(image);
DBImage1->Picture->Graphic->LoadFromStream(stream);
delete image;

//do for metafile
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");


TBlobStream* stream = new TBlobStream(field, bmRead);

DBImage1->Picture->Metafile->LoadFromStream(stream);

//do for icon
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");


TBlobStream* stream = new TBlobStream(field, bmRead);

DBImage1->Picture->Icon->LoadFromStream(stream);

Kevin Berry

unread,
Dec 24, 1999, 3:00:00 AM12/24/99
to

Kevin Berry

unread,
Dec 25, 1999, 3:00:00 AM12/25/99
to
ps. remember to clean up streams after each section for jpg, metafile, and
icon:

delete stream;

Kevin Berry

unread,
Dec 25, 1999, 3:00:00 AM12/25/99
to
Here's how to both load different file formats and retrieve them from
database BLOB fields using a TDBImage component.

#include <jpeg.hpp>

[comment:] register JPEG class in form create


DBImage1->Picture->RegisterFileFormat(__classid(TJPEGImage), "jpg",
"JPEG File", __classid(TJPEGImage));

[comment:] code loads bmp, emf, ico, jpg images into the database
if (OpenPictureDialog1->Execute())


{
Table1->Edit();
TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");

field->LoadFromFile(OpenPictureDialog1->FileName);
Table1->Post();
}

/*


To retrieve images you should set your DBImage1 control's AutoDisplay
property to false. Then do one of the following based on the image type in
the database:

*/

[comment:] do for jpeg


TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");
TBlobStream* stream = new TBlobStream(field, bmRead);
TJPEGImage* image = new TJPEGImage;
DBImage1->Picture->Assign(image);
DBImage1->Picture->Graphic->LoadFromStream(stream);

delete stream;
delete image;

[comment:] do for metafile


TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");
TBlobStream* stream = new TBlobStream(field, bmRead);
DBImage1->Picture->Metafile->LoadFromStream(stream);

delete stream;

[comment:] do for icon


TBlobField* field = (TBlobField*)Table1->FieldByName("FIELDNAME");
TBlobStream* stream = new TBlobStream(field, bmRead);
DBImage1->Picture->Icon->LoadFromStream(stream);

delete stream;

[comment:] do for bitmap
DBImage1->LoadPicture();

A TImage component will work just fine for everything but the bitmap
section. The only thing you get from the TDBImage component, is the ability
to load bitmaps straightforwardly. If you used code for bitmaps as was done
for metafiles, and icons, you wouldn't need the TDBImage component at all.

The image component detects the image format correctly based on the file
extension when loading and saving to files. Someday, somebody will probably
enhance the TDBImage component to detect the correct picture format from
streams too.

0 new messages