dkeene
asked on
Loading Bitmap into ImageList
Hi, All
I have saved a ImageList using the ImageEditor to a bitmap file. They are nice small bitmaps on a clFuchsia background. When I try to load them into an ImageList, I can't seem to specifiy the width/height, and the ImageList doesn't seem to figure it out correctly. The bitmap is 9 images by 9 images.
When I load them, the first nine are perfect, but the rest are blank. This is in a component that I am building. Also, no matter how I change the button size, they stay the same!
fImageList:=TImageList.Cre ate(Self);
ABitmap:=TBitmap.Create;
ABitmap.LoadFromFile('c:\P Man\dkcomp onents\Too lBitmaps.b mp');
fImageList.AddMasked(ABitm ap, clFuchsia);
ABitmap.Free;
for MyCount := 0 to 10 - 1 do begin
MyButton:=TToolButton.Crea te(Self);
with MyButton do begin
MyButton.Parent:=TWinContr ol(fToolBa r);
MyButton.Width:=150;
MyButton.ImageIndex:=MyCou nt;
MyButton.Visible:=True;
end;
end;
Any Thoughts?
Thanks
I have saved a ImageList using the ImageEditor to a bitmap file. They are nice small bitmaps on a clFuchsia background. When I try to load them into an ImageList, I can't seem to specifiy the width/height, and the ImageList doesn't seem to figure it out correctly. The bitmap is 9 images by 9 images.
When I load them, the first nine are perfect, but the rest are blank. This is in a component that I am building. Also, no matter how I change the button size, they stay the same!
fImageList:=TImageList.Cre
ABitmap:=TBitmap.Create;
ABitmap.LoadFromFile('c:\P
fImageList.AddMasked(ABitm
ABitmap.Free;
for MyCount := 0 to 10 - 1 do begin
MyButton:=TToolButton.Crea
with MyButton do begin
MyButton.Parent:=TWinContr
MyButton.Width:=150;
MyButton.ImageIndex:=MyCou
MyButton.Visible:=True;
end;
end;
Any Thoughts?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Let's say that you have a simple application with a form, a tbutton and your TImageList called MyImageList with every needed glyph stored in it.
Well, just save you timagelist component as follows:
procedure TForm1.Button1Click(Sender
begin
WriteComponentResFile('c:\
end;
(You have to do this just one time as you've done for your bitmap)
Well, now that you've saved yor imagelist you can once load it in your component as follows:
FImageList:=TImageList.Cre
try
ReadComponentResFile('c:\P
except
MessageDlg('Warning! Images bin file may be corrupted or do not exists!',mtWarning,[mbOK],
end;
for MyCount := 0 to FImageList.count - 1 do begin
MyButton:=TToolButton.Crea
with MyButton do begin
MyButton.Parent:=TWinContr
MyButton.Width:=150;
MyButton.ImageIndex:=MyCou
MyButton.Visible:=True;
end;
end;
That's all. Bin file is smallest than the bitmap, fast loadable and protected (nobody could use it as a bitmap).
Hope this help.
F68 ;-)