Board index » cppbuilder » graphics field

graphics field


2004-08-29 05:07:52 PM
cppbuilder6
Hi !
Have anyone some experience how to save jpeg picture in paradox table
(TTable) with graphics field type ?
In paradox table I define graphics field type and display it with
TDBImage component...
But how can I load and save selected image from myfile.jpg ?
I'm using BCB6 Prof. and WinXP Prof. ...
Regards
Borut
 
 

Re:graphics field

"Borut" < XXXX@XXXXX.COM >wrote:
Quote
[...] how can I load and save selected image from myfile.jpg ?
You need to save the image as a blob data type. The following
demonstrates taking right off of the disk:
//-------------------------------------------------------------
TBlobStream *pBlob = NULL;
TFileStream *pFile = NULL;
try
{
// start transactions
// open the dataset
// set the dataset in edit mode
pBlob = (TBlobStream *) DataSet1->CreateBlobStream(DataSet1->FieldByName("field name"), bmReadWrite);
pBlob->Seek(0, soFromBeginning);
pFile = new TFileStream( "SomeFileName", fmOpenRead);
pBlob->CopyFrom( pFile, pFile->Size);
// post
// close
// commit transactions
}
catch( Exception &E )
{
MessageDlg("Error Saving Image : " + E.Message, mtError, TMsgDlgButtons() << mbOK, 0);
// rollback transactions
}
delete pBlob;
delete pFile;
//-------------------------------------------------------------
Read it directly into a TPicture. If you also want to display
it, use a TImage instead and alter the code to read:
Image1->Picture...
and don't forget to:
#include <jpeg.hpp>
//-------------------------------------------------------------
TBlobStream *pBlob = NULL;
try
{
// set select sql
// open the dataset
pBlob = (TBlobStream *) DataSet1->CreateBlobStream(DataSet1->FieldByName("field name"), bmRead);
if( pBlob->Size>0 ) Picture1->LoadFromStream( pBlop );
else throw Exception("Picture field is empty.");
// close the dataset
}
catch( Exception &E )
{
MessageDlg("Error Reading Image : " + E.Message, mtError, TMsgDlgButtons() << mbOK, 0);
}
delete pBlob;
//-------------------------------------------------------------
~ JD
 

Re:graphics field

Thanks JD
it's works
Regards
Borut
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Borut" < XXXX@XXXXX.COM >wrote:
>[...] how can I load and save selected image from myfile.jpg ?

You need to save the image as a blob data type. The following
demonstrates taking right off of the disk:

//-------------------------------------------------------------
TBlobStream *pBlob = NULL;
TFileStream *pFile = NULL;
try
{
// start transactions
// open the dataset
// set the dataset in edit mode
pBlob = (TBlobStream *)
DataSet1->CreateBlobStream(DataSet1->FieldByName("field name"),
bmReadWrite);
Quote
pBlob->Seek(0, soFromBeginning);
pFile = new TFileStream( "SomeFileName", fmOpenRead);
pBlob->CopyFrom( pFile, pFile->Size);
// post
// close
// commit transactions
}
catch( Exception &E )
{
MessageDlg("Error Saving Image : " + E.Message, mtError,
TMsgDlgButtons() << mbOK, 0);
// rollback transactions
}
delete pBlob;
delete pFile;
//-------------------------------------------------------------


Read it directly into a TPicture. If you also want to display
it, use a TImage instead and alter the code to read:

Image1->Picture...

and don't forget to:

#include <jpeg.hpp>

//-------------------------------------------------------------
TBlobStream *pBlob = NULL;
try
{
// set select sql
// open the dataset
pBlob = (TBlobStream *)
DataSet1->CreateBlobStream(DataSet1->FieldByName("field name"), bmRead);
if( pBlob->Size>0 ) Picture1->LoadFromStream( pBlop );
else throw Exception("Picture field is empty.");
// close the dataset
}
catch( Exception &E )
{
MessageDlg("Error Reading Image : " + E.Message, mtError,
TMsgDlgButtons() << mbOK, 0);
}
delete pBlob;
//-------------------------------------------------------------

~ JD

 

{smallsort}