我在delphi下,用adotable+aseccc数据库存取图像,用了内存流的技术,不知道为什么只能存不能取?一下是我的代码:需要声明一点:其中dbimage1 只是当做image用.
//存图像
procedure TForm1.Button1Click(Sender: TObject);
var bmpstream:Tmemorystream;
begin
   bmpstream:=tmemorystream.Create;
  try
   dbimage1.Picture.Bitmap.SaveToStream(bmpstream);
   adotable1.Open;
   adotable1.Insert;
   (adotable1.FieldByName('照片')as TBlobField).LoadFromStream(bmpstream);
   adotable1.Post;
   finally
   bmpstream.Free;
   end;end;
//取图像
procedure TForm1.Button2Click(Sender: TObject);
var bmpstream:Tmemorystream;
begin
    bmpstream:=Tmemorystream.Create;
  try
    adotable1.Open;
    adotable1.First;
    (adotable1.FieldByName('照片')as tblobfield).SaveToStream(bmpstream);
    dbimage1.Picture.Bitmap.LoadFromStream(bmpstream);
   if   dbimage1.Picture.Bitmap.Empty  then
        showmessage('dkk');
   finally
   bmpstream.Free;
   end;

解决方案 »

  1.   

    不介意的话。。在存和取中各加入一条adotable1.reflesh和adotable1.close
    这可能是因为表锁的原因吧。。SQL是用独占的方式对一个表进行处理的。。
    不知道能否行得通!!
      

  2.   

    bmpStream.Position := 0; // 添加这一行
    (adotable1.FieldByName('照片')as TBlobField).LoadFromStream(bmpstream);bmpStream.Position := 0; // 添加这一行
    dbimage1.Picture.Bitmap.LoadFromStream(bmpstream);
      

  3.   

    可能就像windofsun说的,你在流复制之前要调整Position
      

  4.   

    你的取图像过程的
    dbimage1.Picture.Bitmap.LoadFromStream(bmpstream);
    一开始就遇到EOF