image读取数据中的图片问题

shepengtao 2005-03-08 10:57:20
请教:我想在image中装载一副图片后,用
stream:=TMemoryStream.Create;
img.Picture.Graphic.SaveToStream(stream);
TBlobField(adoq1.FieldByName('Pic')).LoadFromStream(stream);
存入数据库中,
然后 stream := TMemorystream.Create;
try
TBlobField(adoq1.FieldByName('pic')).SaveToStream(stream);
stream.Position:=0;
frm_photo.img1.Picture.Graphic.LoadFromStream(stream);
finally
stream.Free;
end;
再从数据中显示图片,怎么老是抱地址访问错误?请教!!
...全文
189 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
caiso 2005-03-12
  • 打赏
  • 举报
回复
顶一下@@
ss__328 2005-03-11
  • 打赏
  • 举报
回复
刚写的代码, 正确的,你自己检查下

function TjpgPic.SaveToDB(TypeID: string): boolean;
var MS: TMemoryStream;
cdsPic: TClientDataSet;
SQLStr:string;
begin
if not GraphExisted then
Exit;
cdsPic := TClientDataSet.Create(Application);
with cdsPic do
begin
SQLStr := 'Select * from ' + FGraphTableName + ' Where ' +
FTypeFieldName + '=''' + TypeID + '''';
OpenSQL(SQLStr,cdsPic);
if not Eof then
Edit
else
begin
Insert;
FieldByName(FTypeFieldName).AsString := TypeID;
end;
MS := TMemoryStream.Create;
try
FjpgPic.SaveToStream(MS);
TBlobField(FieldByName(FGraphFieldName)).LoadFromStream(MS);
finally
Ms.free;
end;
Post;
ApplyUpdates(-1);
end;
Result := true;
end;
ss__328 2005-03-11
  • 打赏
  • 举报
回复
function TjpgPic.LoadFromDB(TypeID: string): boolean;
var MS: TMemoryStream;
cdsPic: TClientDataSet;
SQLStr:string;
begin
cdsPic := TClientDataSet.Create(Application);
with cdsPic do
begin
SQLStr := 'Select * from ' + FGraphTableName + ' Where ' +
FTypeFieldName
+ '=''' + TypeID + '''';
OpenSQL(SQLStr,cdsPic);
MS := TMemoryStream.Create;
try
if not Eof then
begin
if TBlobField(FieldByName(FGraphFieldName)).IsNull then
Exit;

TBlobField(FieldByName(FGraphFieldName)).SaveToStream(MS);
MS.Position := 0;
FjpgPic.LoadFromStream(MS);
GraphExisted := true;
Result := true
end else
begin
Result := False;
GraphExisted := false;
end;
finally
Ms.free;
end;
end;
end;
richard_ouyang 2005-03-11
  • 打赏
  • 举报
回复
你是不是什么东西没有创建就在使用了。请查找一下。
shepengtao 2005-03-08
  • 打赏
  • 举报
回复
不是这样的,我这两段代码是在两个地方写的
tiankj 2005-03-08
  • 打赏
  • 举报
回复
stream:=TMemoryStream.Create;
img.Picture.Graphic.SaveToStream(stream);
TBlobField(adoq1.FieldByName('Pic')).LoadFromStream(stream);
freeandnil(stream);//
存入数据库中,

然后 stream := TMemorystream.Create;
try
TBlobField(adoq1.FieldByName('pic')).SaveToStream(stream);
stream.Position:=0;
frm_photo.img1.Picture.Graphic.LoadFromStream(stream);
finally
stream.Free;
end;

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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