sql server 是的类型定义为image类型
保存
var
jpeg:tjpegimage;
s:string;
begin
if image2.tag=0 then
begin
showmessage('dd');
exit;
end;
s:=extractfilepath(application.ExeName)+'jpeg.jpg';
jpeg:=tjpegimage.Create ;
jpeg.Assign(Image2.Picture);
jpeg.CompressionQuality :=75;
jpeg.Compress ;
jpeg.SaveToFile(s);
if dm.DS_ygphoto.Active then
begin
if form1.Image1.Tag =0 then
begin
dm.DS_YGPHOTO.Insert ;
dm.DS_YGPHOTO.FieldByName('bh').AsString :=dm.DS_YGhmc.fieldbyname('bh').AsString ;
tblobfield(dm.DS_YGPHOTO.FieldByName('photo')).LoadFromFile(s);
end;
if form1.Image1.tag =1 then
begin
dm.DS_YGPHOTO.Edit ;
tblobfield(dm.DS_YGPHOTO.FieldByName('photo')).LoadFromFile(s);
end;
dm.DS_YGPHOTO.Post;
end;
freeandnil(jpeg);
end;
读取显示
var
JPEG:TJPEGIMAGE;
stream: TMemoryStream;
begin
image1.Picture.Assign(nil);
if dm.DS_YGPHOTO.FieldByName('photo').IsNull then
begin
image1.Tag :=0;
panel2.Caption :='无照片';
end
else
begin
JPEG:=TJpegimage.Create ;
stream:=TMemoryStream.Create ;
tblobfield(dm.DS_YGPHOTO.FieldByName('photo')).savetostream(stream);
Stream.Seek(0, soFromBeginning);
jpeg.loadfromstream(stream);
image1.Picture.Bitmap.Assign(jpeg);
freeandnil(Jpeg);
freeandnil(stream);
image1.Tag :=1;
end;
要引用jpeg单元