数据库图片存储也读取

procedure TForm1.Button1Click(Sender: TObject);
var
Ms:TmemoryStream;
jpg:Tjpegimage;
begin
ms:=TmemoryStream.Create;
Image1.Picture.Graphic.SaveToStream(Ms);
Ms.Position :=0;
DATA_M.ADOQuery_TEMP.Active:=FALSE;
DATA_M.ADOQuery_TEMP.SQL.Add('SELECT * FROM JZ_JZGIMG')  ;
DATA_M.ADOQuery_TEMP.Active:=TRUE;
DATA_M.ADOQuery_TEMP.Edit;
TBlobField(DATA_M.ADOQuery_TEMP.FieldByName('ZP')).LoadFromStream(Ms);
DATA_M.ADOQuery_TEMP.Post;
Ms.Free ;

end;

 

 

var
mStream:TMemoryStream;
JpgFile:TjpegImage;
begin
if not DATA_M.ADOQuery_TEMP.FieldByName('ZP').IsNull then begin ;
mStream:=TMemoryStream.Create ;
JpgFile:=TjpegImage.Create ;
TBlobField(DATA_M.ADOQuery_TEMP.FieldByName('ZP')).SaveToStream(mStream);//顯示的轉換為BlobFiled並保存至內存流
mStream.Position :=0;
jpgfile.LoadFromStream(MStream);
image2.Picture.Assign(JpgFile);
end
else begin
image2.Picture :=nil;
end;
end;

你可能感兴趣的:(数据库图片存储也读取)