从list中取图标,刷新时内存泄漏 如何解决? ( 积分: 100 )

  • 主题发起人 hitman007260
  • 开始时间
没想到这么难
 
大富翁的高手们哪????
 
改成如下试试
for i:=0 to imagelist.Count-1 do
begin
image:=imagelist.items;
w:=image.Picture.Bitmap.Width;
h:=image.Picture.Bitmap.Height;
image.Canvas.CopyMode:=cmNotSrcCopy;
image.Canvas.CopyRect(Rect(0,0,w,h),image.Canvas,Rect(0,0,w,h));
end;
 
语法错误
 
还有我想知道为什么出错
 
Missing operator or semicolon
 
该了一下 试了 还是不行
 
for i:=0 to imagelist.Count-1 do
begin
image:=imagelist.items;
w:=image.Picture.Bitmap.Width;
h:=image.Picture.Bitmap.Height;
image.Canvas.CopyMode:=cmNotSrcCopy;
Rect.Left:=0;
Rect.Top:=0;
Rect.Right:=w;
Rect.Bottom:=h;
image.Canvas.CopyRect(Rect ,image.Canvas,Rect);
end;

图像闪烁 内存增加
 
单从这一段代码来看 不存在内存泄漏的问题 由于不停刷新图像 内存变化是正常的 涨跌应该会在一个幅度内
 
不是 时间一长 程序都崩溃了
报 memory out 错误
 
dfw真的没落了吗??
 
我简单写了一个程序,没发现内存泄漏啊?
代码如下:
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Image1: TImage;
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
imagelist: TList;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var image: Timage;
i, w, h: integer;
hdc1, hdc2: HDC;
begin
for i:=0 to imagelist.Count-1 do
begin
image:=imagelist.items;
w:= image.Picture .Bitmap.Width ;
h:=image.Picture.Bitmap.Height ;
hdc2:=image.Canvas.Handle;
hdc1:=image.Canvas.Handle ;
bitblt(hdc2,0,0,w,h,hdc1,0,0,notsrccopy);
image.repaint();
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
imagelist := TList.Create;
end;

procedure TForm1.FormShow(Sender: TObject);
var image: Timage;
I: Integer;
begin
for I := 0 to 10 - 1 do
begin
image := TImage.Create(Self);
image.Parent := Self;
image.Left := I * 50;
image.Top := 10;
image.Width := 40;
image.Height := 40;
image.AutoSize := False;
image.Stretch := True;
image.Picture.LoadFromFile('c:/1.bmp');
image.repaint();
imagelist.Add(Image);
end;
end;
 
我得在frame中 不知道原因是什马 痛苦啊
 
for i:=0 to imagelist.Count-1 do
begin
image:=trainlist.items;


w:= image.Picture.Bitmap.Width ;
h:=image.Picture.Bitmap.Height ;

ximage:=Timage.create(self);
ximage.Parent:=image.Parent;
ximage.Tag:=image.Tag;
ximage.Width:=image.Width;
ximage.Height:=image.Height;
ximage.top:=image.top;
ximage.left:=image.left;
ximage.Transparent :=true;
ximage.Stretch:=true;
tmp:=tbitmap.create;
tmp.assign(t4image.Picture .Bitmap);
tmp.Canvas.CopyMode:=cmNotSrcCopy;
TheRect.Left:=0;
TheRect.Top:=0;
TheRect.Right:=w;
TheRect.Bottom:=h;
tmp.Canvas.CopyRect(TheRect,t4image.Canvas,TheRect);
ximage.Picture.Bitmap.assign(tmp);

trainlist.items:=ximage;
FreeAndNil(image);
tmp.free;

end;

这样做都不行
 
不知道你想要什么效果,imagelist本身带有draw方法,可以在别的地方绘图,比如:
imagelist1.Draw(MCanvas,4,9,0);
参数说明(canvas的handle,绘图起始坐标x,y,image在list内的编号)
 
有的歧义阿 这里的imagelist 的类型是Tlist不是TImageList
 
这样啊,不过,你的程序也可以用 timagelist来保存图片啊,timagelist的图片可以自定义大小的。另外,我不知道你图片是放在哪里闪烁的?
如果是一串图片需要闪烁,那么可以用listbox设置为自画状态使用,效果不错的。
如果是固定的几个图需要闪烁,那么简单一点的,可以用image时隐时现的方式实现闪烁。
 
使用了Image后必须释放,看你的代码多次使用都没有释放,必然导致内存泄漏。
 
ufo! 能不能不能举个例子
delphixyz Image在那里释放??不光闪烁 我还有别的用处 用完了我就用 FreeAndNil(image);删除了
 
如果楼主的程序不大,且不涉及商业秘密,没使用第三方控件,那么发到我邮箱我帮你调试一下。
我的邮箱: ufo2003@126.com
 
顶部