Image 编码、解码base64图像流delphi

Image 编码、解码base64图像流delphi,image,delphi,stream,decode,encode,Image,Delphi,Stream,Decode,Encode,我正在尝试使用encddecd.pass中的EncodeBase64对图像流进行编码,并将该保存在blob字段中的数据传递到数据库。并在ByTestStream中使用decodebase64检索此内容,该ByTestStream放入一个组件中显示。 该过程完成得很好,但图像未显示在组件中 以下是摘要代码: procedure TProcessSave.Execute; var i : Integer; fileStm : TStream; memStm : TMemoryStream

我正在尝试使用encddecd.pass中的EncodeBase64对图像流进行编码,并将该保存在blob字段中的数据传递到数据库。并在ByTestStream中使用decodebase64检索此内容,该ByTestStream放入一个组件中显示。 该过程完成得很好,但图像未显示在组件中

以下是摘要代码:

procedure TProcessSave.Execute;
var
  i : Integer;
  fileStm : TStream;
  memStm : TMemoryStream;
  encode_plc : string;
begin
  for i := 0 to StrList.Count - 1 do
  begin
    DM.idb_tbl.Append;

    DM.idb_tbl.FieldByName('name').AsString := ExtractFileName(StrList.Strings[i]);  

try
  fileStm := TFileStream.Create(StrList.Strings[i], fmOpenReadWrite);

  memStm := TMemoryStream.Create;

  filestm.Seek(0, soFromBeginning);

  memStm.LoadFromStream(fileStm);

  DM.idb_tbl.FieldByName('file').Value := EncodeBase64(memStm.Memory, memStm.Size);

finally
  fileStm.Free;
  memStm.Free;
end;

DM.idb_tbl.Post;

end;
end;
装载时:

procedure TLoadBar.Execute;
var
  imgStm : TStream;
begin
  with DM.idb_qry do
  begin
    DatabaseName := DM.idb_db.DatabaseName;

    SQL.Text := 'SELECT * FROM pics_tbl';
    Open;

   First;

   while not Eof do
   begin

     try

      imgStm :=TBytesStream.Create(DecodeBase64(FieldByName('file').Value));

      idx := imgBar_iemv.AppendImage;
      imgBar_iemv.SetImageFromStream(idx, imgStm);
      imgBar_iemv.ImageID[idx] := id;

    finally
      imgStm.Free;
    end;

  Next;
end;
end;
end;

然后我使用imgStm在组件中显示图片,但不显示图片。我从组件上确定。你对我的方法中的编码和解码有什么想法?是否有另一种方法可以确保对该问题进行编码和解码?

您不能使用
imgStm
显示图片,因为您的代码创建
imgStm
,然后立即释放它。此外,您的代码根本不尝试以任何方式显示图像,因为它只会创建一个
tbytestream
并立即处理它。您必须创建一个
TBitmap
TJpegImage
(取决于编码的图像类型),使用它的
LoadFromStream
方法,然后将该位图/JPEG分配给
TImage.Picture
属性。您不需要中间流。这就是streams.tanks的全部理由。对于你的答案,我忘了在这里放一部分代码。事实上,我使用ImegeEn组件来显示图像。在这个组件中,有一个方法可以获取流并显示它。我不知道您使用的是什么数据库,但您通常可以将图像作为二进制文件保存到文本、备忘录或blob字段中,而无需任何编码。然后你可以简单地把它读回并保存到一个文件中。谢谢你的回答,我想保护流,因为我想对流使用加密,这对我来说非常重要。