sql server 存储图像??????(全天在线)(50分)

  • 主题发起人 主题发起人 傻子007
  • 开始时间 开始时间

傻子007

Unregistered / Unconfirmed
GUEST, unregistred user!
[h1][blue]
代码:
[b]哪位大虾可以教我如何在delphi中存储图像,sql server中如何定义字段类型,可以指
点指点,小弟全天在线[/b]
[/blue][/h1]
 
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单元
 
后退
顶部