如何清除Image上的图象,释放内存空间?

bill_anson 2006-07-11 03:19:50
Image.Picture.Bitmap.Free;

或 Image->Picture->Graphic := nil;
这样合理吗.
...全文
262 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lunyx 2006-07-12
  • 打赏
  • 举报
回复
image1.Picture:=nil;
虽然已经NILl了..可是下面怎么测都是not nil ???
if image1.Picture=nil then
showmessage('image1 picture is nil')
else showmessage('image1 picture is not nil');
keyz 2006-07-12
  • 打赏
  • 举报
回复
用这一句应该就可以释放了: Image1.Picture:=TPicture.Create;
keyz 2006-07-12
  • 打赏
  • 举报
回复
Image1.Picture:=TPicture.Create;

查VCL,可以看到
procedure TImage.SetPicture(Value: TPicture);
begin
FPicture.Assign(Value);
end;


procedure TPicture.Assign(Source: TPersistent);
begin
if Source = nil then
SetGraphic(nil)
else if Source is TPicture then
SetGraphic(TPicture(Source).Graphic)
else if Source is TGraphic then
SetGraphic(TGraphic(Source))
else
inherited Assign(Source);
end;

procedure TPicture.SetGraphic(Value: TGraphic);
var
NewGraphic: TGraphic;
begin
NewGraphic := nil;
if Value <> nil then
begin
NewGraphic := TGraphicClass(Value.ClassType).Create;
NewGraphic.Assign(Value);
NewGraphic.OnChange := Changed;
NewGraphic.OnProgress := Progress;
end;
try
FGraphic.Free; //<------ 此处释放了原来的图像
FGraphic := NewGraphic; //<--------- 使用新图像
Changed(Self);
except
NewGraphic.Free;
raise;
end;
end;
才子鸣 2006-07-12
  • 打赏
  • 举报
回复
UP 楼上的...晕倒
newfang 2006-07-12
  • 打赏
  • 举报
回复
image1.Picture:=nil;
这也可以??玩笑开大了吧??
psp2003 2006-07-11
  • 打赏
  • 举报
回复
Image.Picture :=nil;
w95927w 2006-07-11
  • 打赏
  • 举报
回复
这个基本上很难 hehe^^

用下面那个只能凑合了

--------------------------------- ...哇哈哈哈 CSDN's forum Explorer
wudi_1982 2006-07-11
  • 打赏
  • 举报
回复
用下面那个

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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