Article View: borland.public.cppbuilder.database.ado
Article #5065Re: TDBImage with different image formats
From: Kevin Berry
Date: Fri, 10 Aug 2001 18:17
Date: Fri, 10 Aug 2001 18:17
58 lines
3375 bytes
3375 bytes
> I tried to load into a record a JPEG image. Since the ordinary TImage is
> capable of doing so, I wondered why the TDBImage isn't (Even though it
> doesn't inherit from TImage, Borland should have allowed us to use other
> formats beside BMPs in a DB).
Until TDBImage works for you as desired, here's my post from two years ago:
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
kevinrberry@charter.net
Technical Details
Message-ID:
<3b742550_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsReferences:
<3b740157_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcd2b,83c8bbc8a162f33f X-Google-Attributes: gidfcd2b,public X-Google-Thread: 10698b,83c8bbc8a162f33f X-Google-Attributes: gid10698b,public X-Google-Thread: 10bf25,83c8bbc8a162f33f X-Google-Attributes: gid10bf25,public X-Google-Thread: fc5f9,83c8bbc8a162f33f X-Google-Attributes: gidfc5f9,public X-Google-Thread: f5db0,83c8bbc8a162f33f X-Google-Attributes: gidf5db0,public X-Google-ArrivalTime: 2001-08-10 11:32:42 PST Reply-To: "Kevin Berry" <kberry@spl.usace.army.mil> From: "Kevin Berry" <kberry@spl.usace.army.mil> Newsgroups: borland.public.cppbuilder.database.ado,borland.public.cppbuilder.database.desktop,borland.public.cppbuilder.database.interbaseexpress,borland.public.cppbuilder.database.multi-tier,borland.public.cppbuilder.database.sqlservers References: <3b740157_1@dnews> Subject: Re: TDBImage with different image formats Date: Fri, 10 Aug 2001 11:17:52 -0700 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 NNTP-Posting-Host: 155.83.128.153 Message-ID: <3b742550_2@dnews> X-Trace: dnews 997467472 155.83.128.153 (10 Aug 2001 11:17:52 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!news.stealth.net!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews