应该是很容易的问题,想拿分的赶紧进! (50分)

  • 主题发起人 主题发起人 jsongy
  • 开始时间 开始时间
J

jsongy

Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样将jpg图象文件存入access数据库的OLE对象类型字段中?
最好能附原代码,谢了!
 
太多了﹗﹗找下老貼﹗﹗
 
大虾们帮帮忙,我现在搜不到以前的帖子!
 
你要搜搜啊。。。

我找找给你
 
我写了两个函数看一下吧

procedure TEmp_Form.SetPicture(EmpID: string; TempQuery: Tadoquery);
var
MS_JpegStream:TMemoryStream;
M_BitMap:TBitMap;
M_Jpeg:TJpegImage;
begin
try
MS_JpegStream:=TMemoryStream.Create;
M_BitMap:=TBitMap.Create;
M_Jpeg:=TJpegImage.Create;
if extractfileext(filename)='.bmp' then
begin
M_BitMap.LoadFromFile(filename);
M_Jpeg.Compress;
M_Jpeg.Assign(M_BitMap);
end
else if extractfileext(filename)='.jpg' then
begin
M_Jpeg.LoadFromFile(filename);
end;
M_Jpeg.SaveToStream(MS_JpegStream);
with tempQuery do
begin
close;
sql.clear;
sql.Add('update userinfo set userphoto_ui=:IMage where userno_ui=:empid');
parameters.ParamByName('empid').value:=trim(empid);
parameters.ParamByName('image').LoadFromStream(MS_JpegStream,ftblob);
ExecSQL;
end;
finally
MS_JpegStream.Free;
M_BitMap.Free;
M_Jpeg.Free;
end;
end;

procedure TEmp_Form.GetPicture(EmpID: string; TempQuery: TAdoQuery);
var
MS_JpegStream:TMemoryStream;
begin
try
MS_JpegStream:=TMemoryStream.Create;
with tempQuery do
begin
close;
sql.clear;
sql.Add('select userphoto_ui from userinfo where userno_ui=:empid');
parameters.parambyname('empid').value:=trim(empid);
Open;
end;
if tempquery.FieldByName('userphoto_ui').isnull then
begin
emp_image.Picture.Graphic:=nil;
end
else
begin
(tempQuery.FieldByName('userphoto_ui') as tblobfield).savetostream(MS_JpegStream);
emp_image.Picture.Graphic:=nil;
emp_image.Picture.Graphic:=TJpegImage.Create;
MS_JpegStream.Position:=0;
emp_image.Picture.Graphic.LoadFromStream(MS_JpegStream);
end;

finally
MS_JpegStream.Free;
end;
end;
你略做一下修改就可以了
 
转!
你照着下面的方法就行.另外,你是否有一个DBIMAGE控件?因为DBIMAGE控件只能打开BMP格式
的图片,所以,你直接读JPG的要出问题.要先转化一下格式就可.另外,在uses部分要加上
Jpeg;

:DBImage.Picture.bitmap.assign(JpgPic);//加在下面代码中,DBIMAGE就可显示JPG图片了.
var tempStream:TMemoryStream;
JpgPic:TJpegImage;
begin
try
JpgPic:=TJpegImage.Create;
tempStream:=TMemoryStream.Create;
tempStream.clear;
adoquery1.Append;
JpgPic.LoadFromFile(openpicturedialog1.filename);
DBImage.Picture.bitmap.assign(JpgPic);//若你想DBIMAGE显示JPG图像就可这样.
JpgPic.SaveToStream(tempStream);
tblobfield(adoquery1.FieldByName('image')).LoadFromStream(tempStream) ;
adoquery1.Post;
finally
JpgPic.Free;
tempStream.Free;
end;
这是保存的方法,读取图片也要转换一下才行.
 
哈哈,试试看!
 
多人接受答案了。
 
后退
顶部