关于数据库图像存储的问题

minixia 2002-03-06 08:58:36
请问怎样利用ado控件把图片存到数据库中。
...全文
73 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
minixia 2002-03-07
  • 打赏
  • 举报
回复
谢谢大家
creativitysoft 2002-03-07
  • 打赏
  • 举报
回复
#include <jpeg.hpp>

void __fastcall TForm1::Button3Click(TObject *Sender)
{
// query the image table
Query->SQL->Text = "select * from image_test\n"
"where string_field = 'space.jpg'";
Query->Active = true;

// 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());

Query->Active = false;
}
creativitysoft 2002-03-07
  • 打赏
  • 举报
回复
#include <jpeg.hpp>

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();
}
creativitysoft 2002-03-07
  • 打赏
  • 举报
回复
#include <jpeg.hpp>

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();
}

BCB 2002-03-07
  • 打赏
  • 举报
回复
这我做过,用TBlobStream写
我不懂电脑 2002-03-06
  • 打赏
  • 举报
回复
TBlobStream 是典型用法。
zsr 2002-03-06
  • 打赏
  • 举报
回复
TBlobStream
hotxu 2002-03-06
  • 打赏
  • 举报
回复
TUserPotopicture->LoadFromFile(PotoName);
jones129 2002-03-06
  • 打赏
  • 举报
回复
最好还是不要这样做,一般都是在数据库中指明其路径。

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧