使用以下SQL:
INSERT INTO team (name, photo) VALUES (:name, :photo);
字符串我已经在TImage组件中加载了一个图像,并在“people”表中加载了一个Bytea字段。有人能帮我吗?
jvidinwx1#
将图像插入Postgres BYTEA字段的代码示例如下:
procedure TForm1.SaveBlobClick(Sender: TObject);var stream: TMemoryStream;//TBlobStream TStream format: integer;begin with query1 do begin sql.Clear; stream := TMemoryStream.Create; sql.Add('INSERT INTO tmp_blob (image) VALUES (:blob);'); TmpJpg.SaveToStream(stream); ParamByName('blob').LoadFromStream(stream, ftGraphic ); ExecSql; stream.Free; end;end;
procedure TForm1.SaveBlobClick(Sender: TObject);
var
stream: TMemoryStream;//TBlobStream TStream
format: integer;
begin
with query1 do
sql.Clear;
stream := TMemoryStream.Create;
sql.Add('INSERT INTO tmp_blob (image) VALUES (:blob);');
TmpJpg.SaveToStream(stream);
ParamByName('blob').LoadFromStream(stream, ftGraphic );
ExecSql;
stream.Free;
end;
字符串读取图像:
procedure TForm1.BLoadBlobClick(Sender: TObject);var stream: TStream;//TMemoryStream g : TGraphic;begin with query1 do begin close; sql.clear; sql.add('SELECT * FROM tmp_blob LIMIT 1' ); Open; Stream := query1.CreateBlobStream(fieldByName('image') , bmRead ); tmpJpg.LoadFromStream(stream); image1.Picture.Bitmap := tmpJpg.toBitmap; close; Stream.Free; end;end;
procedure TForm1.BLoadBlobClick(Sender: TObject);
stream: TStream;//TMemoryStream
g : TGraphic;
close;
sql.clear;
sql.add('SELECT * FROM tmp_blob LIMIT 1' );
Open;
Stream := query1.CreateBlobStream(fieldByName('image') , bmRead );
tmpJpg.LoadFromStream(stream);
image1.Picture.Bitmap := tmpJpg.toBitmap;
Stream.Free;
型注意:我使用SynGdiPlus库中的TJpegImage组件来加载和保存映像
SynGdiPlus
TJpegImage
1条答案
按热度按时间jvidinwx1#
将图像插入Postgres BYTEA字段的代码示例如下:
字符串
读取图像:
型
注意:我使用
SynGdiPlus
库中的TJpegImage
组件来加载和保存映像