存储图片到Access中(100分)

H

huxhang

Unregistered / Unconfirmed
GUEST, unregistred user!
存储图片到Access中。小面的问题帮我一下,谢谢!
procedure TForm1.Button1Click(Sender: TObject);
var
strm:tmemorystream;
ext:string;
begin
t_pz.Active:=true;
if openpicturedialog1.Execute then
image1.Picture.LoadFromFile(openpicturedialog1.FileName );
if image1.picture.Graphic <> nil then //避免image1中无图像保存出错
begin
ext:=extractfileext(openpicturedialog1.FileName ); //取出文件的扩展名
strm := tmemorystream.Create ;
try
image1.Picture.Graphic.SaveToStream(strm);
t_pz.Edit ;
strm.Position:=0;
tblobfield(t_pz.FieldByName('photo')).LoadFromStream(strm);
//如需直接由文件保存可采用如下注释行
//TBlobField(T_pz.FieldByName('photo')).LoadFromFile(OpenPictureDialog1.FileName);
//以下记录保存到数据库的图像格式
if uppercase(ext) = '.BMP' then
t_pz.FieldByName('isbmp').Value := 1 //BMP型图像数据
else if (uppercase(ext) = '.JPG') OR ( uppercase(ext) = '.JPEG') Then
t_pz.FieldByName('isbmp').Value := 0; //JPEG型图像数据
showmessage('用Assign办法存储到Access,t_pz.Edit就出问题,用 t_pz.append才行?');
t_pz.post ; //上面用 t_pz.Edit就出问题,用 t_pz.append才行 ?
finally
strm.Free ; //如strm采用tblobstream类,程序运行到该语句会出现问题
end;
end;
t_pz.Active:=false;
end;
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
965
SUNSTONE的Delphi笔记
S
I
回复
0
查看
488
import
I
顶部