PDA

View Full Version : [SOLVED] Best way to write TCanvas to an Icon?


Glenn1234
08-25-2009, 04:17 AM
As the topic indicates. I figured out a way from some research (involving TImageList), but it really isn't working all too well. So I'm wondering what people typically do to draw icons and write them within their applications?

Glenn1234
08-29-2009, 08:32 PM
No ideas on this one, or is TImageList the best I can do when it comes to writing icons using TCanvas?

Norrit
08-31-2009, 09:19 AM
Well, I would use a TImageList indeed... so what is your code that "isn't working all too swell" ???

Glenn1234
09-01-2009, 04:07 AM
Well, I would use a TImageList indeed... so what is your code that "isn't working all too swell" ???

I have something that works right on one system but not another. I'm trying to actively draw a TBitmap and then post it to an icon using TImageList. The test system, where the code was developed, works as intended but on another other system, all that shows up is garbage.


procedure TForm1.SpinEdit1Change(Sender: TObject);
var
myBitmap: TBitmap;
begin
ProgressBar1.Position := SpinEdit1.Value;
myBitMap := TBitmap.Create;
try
with myBitmap do
begin
Width := 32;
Height := 32;
Canvas.Font.Height := 32;
Canvas.Font.Color := clRed;
Canvas.TextOut(0, 0, intToStr(SpinEdit1.Value));
end;
With TImageList.CreateSize(MyBitmap.Width, MyBitmap.Height) do
try
AllocBy := 1;
AddMasked(MyBitmap, clWhite);
GetIcon(0, MyIcon.Icon); // icon drawn here
finally
Free;
end;
finally
MyBitmap.free;
end;