sql server 2005 字段类型为 image
delphi使用的单元为jpeg, db, dbtables;
delphi 存储图片代码片段
procedure TForm1.btnPostClick(Sender: TObject);
var
lMemoStream : TMemoryStream;
jpg : TJpegImage;
begin
lMemoStream := TMemoryStream.Create;
jpg := TJpegimage.Create;
jpg.Assign(Img.Picture.Graphic);
jpg.SaveToStream(lMemoStream);
lMemoStream.Position := 0;
TBlobField(dm1.adoqrytea.fieldbyname('image')).LoadFromStream(lMemoStream);
dm1.adoqrytea.Post;
end;
delphi从数据库读取到image中的代码片段
procedure TForm3.FormShow(Sender: TObject);
var
MyJPEG : TJPEGImage;
MS : TMemoryStream;
begin
MyJPEG:=TJPEGImage.Create;
MS:=TMemoryStream.Create;
if not dm1.adostuview.Active then
dm1.adostuview.Open;
with dm1.adostuview do
begin
TBlobField(dm1.adostuview.Fields[9]).SaveToStream(MS);
ms.Position := 0;
MyJPEG.LoadFromStream(MS);
Img.picture.assign(MyJPEG);
MyJPEg.free;
MS.free;
end;
end;
|
请发表评论