在数据库中保存图片出错?

ChinaZhou 2005-10-07 01:04:38
我用的是DELPHI,想把图片保存到ACCESS中,保存WINDOWS自带的样品(42K)好用,但想保存600K的文件就提示错误。大概是BLOB的宽是非法的”
...全文
190 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ChinaZhou 2005-10-08
  • 打赏
  • 举报
回复
原代码是这样的:
if OleContainer1.Modified then
begin
Stream := TBlobStream(table1.CreateBlobStream(table1.FieldByName(iv_oleField), bmReadWrite));
if OleContainer1.State <> osEmpty then
begin
OleContainer1.SaveToStream(Stream);
OleContainer1.Close ;
end
else
begin
Stream.Truncate ;
end;
Stream.Free;
end;
try
table1.Post;
except
on E: EDBEngineError do
;// pass
end;
错误提示:
EDBEngineError :Invalid BLOB length
wdswcy 2005-10-08
  • 打赏
  • 举报
回复
procedure Tchgform.Button7Click(Sender: TObject);
var
filename :string;
Ms:TmemoryStream;
begin
if openpic.Execute then
begin
filename:=openpic.FileName;
ms := TMemorystream.Create();
try
dmform.ado_connect_yc.BeginTrans;
ms.LoadFromFile(filename);
Ms.Position :=0;
image1.Picture.LoadFromFile(filename);
with tadoquery.Create(self) do
begin
close;
connection:=dmform.ado_connect_yc;
sql.Clear;
sql.Add('select * from aa where id=1');
open;
edit;
TBlobfield(FieldByName('img')).LoadFromStream(Ms);
post;
free;
end;
dmform.ado_connect_yc.CommitTrans;
ms.Free;
except
begin
msgboxi('数据提交错误,你所做的更改无效,请重试');
dmform.ado_connect_yc.rollbacktrans;
end;
end;



end;

end;
ChinaZhou 2005-10-08
  • 打赏
  • 举报
回复
字段设置为ole 对象
采用保存路径的方法后,可调用图片
但不是最终想要的结果,希望是能够把图片保存到数据中,图片本身是JPG格式是的,大概600k
天成01 2005-10-08
  • 打赏
  • 举报
回复
反问下 你的数据库表的字段属性设置对不对?
人鱼传说 2005-10-07
  • 打赏
  • 举报
回复
建议转成JPG后再保存,1024*768大小的图片也不过几十K
常遇道 2005-10-07
  • 打赏
  • 举报
回复
图片直接存入access显得access太大,速度很慢,请问如何保图片保存在某个目录下,当数据库表的数据指针指在不同的记录时,要显示相对应图片?


if OpenDialog1.Execute then
begin
ADOQuery1.Edit;
ADOQuery1.FieldByName('Path').AsString :=ExtractFilePath(OpenDialog1.FileName) + ExtractFileName(OpenDialog1.FileName);
ADOQuery1.Post;
end;
常遇道 2005-10-07
  • 打赏
  • 举报
回复
你说的图片有多大?分块存储应该就是将图片划分成几份,然后每个字段存一份吧?比如说
一张大图片,你将其平均分成四份,上下左右各又成了一份图片,再用普通的保存图片的方法
保存进数据库.取出时,再将其四份取出来,再还原拼成一副大图片即可.要用到的函数,只一
个,BitBlt就够了.
相关格式,下面是一部分,你还是找帮助吧,或搜索一下,这儿应该有许多相关内容.
The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
BOOL BitBlt(
HDC hdcDest, // handle to destination device context
int nXDest, // x-coordinate of destination rectangle's upper-left corner
int nYDest, // y-coordinate of destination rectangle's upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coordinate of source rectangle's upper-left corner
int nYSrc, // y-coordinate of source rectangle's upper-left corner
DWORD dwRop // raster operation code
);
yangmanyuan 2005-10-07
  • 打赏
  • 举报
回复
给你一个建议,用tblobfield(field).loadfromfile应该可以,还有大图片最好不要用access这种数据库,或者sql这种数据库在2m以上也有问题。
winxkm 2005-10-07
  • 打赏
  • 举报
回复
你把你的代码贴出来看看

2,495

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧