// Create a memory stream and copy the image from the blob
// field into the stream. Note that Queryimage_field is a
// a persistent TBlobField created from the fields editor
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
Queryimage_field->SaveToStream(stream.get());
// create a jpeg image object, and tell it to load the jpeg
// from the memory stream
stream->Position = 0;
std::auto_ptr<TJPEGImage> jpeg(new TJPEGImage);
jpeg->LoadFromStream(stream.get());
// Now load the jpeg into the image. This step
// decompresses the JPEG to a bitmap
Image1->Picture->Bitmap->Assign(jpeg.get());
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// load a bitmap into a TBitmap object
std::auto_ptr<TBitmap> bitmap(new TBitmap;
bitmap->->LoadFromFile("androm.bmp");
// create a jpeg object and assign the bitmap
// to the jpeg. This performs the JPEG compression step.
std::auto_ptr<TJPEGImage> jpeg(new TJPEGImage);
jpeg->Assign(bitmap.get());
// Now create a stream object and write the compressed JPEG
// image to the stream. Once we have the JPEG data in the
// stream, we can get it into the database.
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
jpeg->SaveToStream(stream.get());
stream->Position = 0;
// Save the stream to the database. This is exactly like Example 1
Query1->Params->ParamByName("string_field")->AsString = "androm.bmp";
Query1->Params->ParamByName("image_field") ->SetBlobData(stream->Memory,
stream->Size);
// execute the query to perform the insert
Query1->ExecSQL();
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
// create a jpeg object and assign the bitmap of the
// TImage to the jpeg object.
std::auto_ptr<TJPEGImage> jpeg(new TJPEGImage);
jpeg->Assign(Image1->Picture->Bitmap);
// Now create a stream object and write the compressed JPEG
// image to the stream. Once we have the JPEG data in the
// stream, we can get it into the database.
std::auto_ptr<TMemoryStream> stream (new TMemoryStream);
jpeg->SaveToStream(stream.get());
stream->Position = 0;
// Save the stream to the database. This is exactly like Example 1
Query1->Params->ParamByName("string_field")->AsString = "androm.bmp";
Query1->Params->ParamByName("image_field") ->SetBlobData(stream->Memory,
stream->Size);
// execute the query to perform the insert
Query1->ExecSQL();
}