Link to home
Start Free TrialLog in
Avatar of Bobcsi
Bobcsi

asked on

Load a large icon from resource

Hi!

I want load a icon from resource to a TImage or TImagelist.
I have a ICON64 icon resource. Size: 64 x 64.

When load icon, i get the icon, but size is 32 x 32. Why?

Code:

image1.picture.icon.Handle:=loadicon(HInstance, 'ICON64');

Thx the answers

Bobcsi
Avatar of vacerose
vacerose

From Windows API help

LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes.

ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bobcsi

ASKER

Thx

Fast answer

Solution:

image1.picture.icon.Handle:=loadimage(HInstance, 'ICON64',IMAGE_ICON,64,64,LR_LOADTRANSPARENT);

Bobcsi
Avatar of Bobcsi

ASKER

New problem:)

Code:

var icon:TIcon;
begin
  icon:=ticon.create;
  icon.handle:=loadimage(HInstance, 'ICON64',IMAGE_ICON,64,64,LR_LOADTRANSPARENT);
  imagelist1.AddIcon(icon);
  image1.picture.icon.assign(icon);
end;

When run AddIcon a get an error: "invalid image size"
Because I set the imagelist1 width,height to 64.

Why?

Bobcsi
Please post your icon somewhere where I can download it. I can not create a 64x64 icon using the tools I have.
I can not get to that server, can't figure out why, would you just email it to eddie dot shipman at gmail dot com
Avatar of Bobcsi

ASKER

ok, posted.
Somewhere between setting the icon's height/width and the CheckImage function in ImgList, the height/width gets reset to
32x32. I'll see if I can figure out why.

Loading into a TImage is no problem load it into the TImage before trying to load it to the ImageList.

Here is how I rearranged it:

var
  icon: TIcon;
begin
  icon        := ticon.create;
  icon.Height := 64;
  icon.Width := 64;
  icon.handle := loadimage(HInstance, 'ICON64', IMAGE_ICON, 64, 64, LR_LOADTRANSPARENT);
  image1.picture.icon.assign(icon);
  // Still gettting the Invalid image size error here
  imagelist1.AddIcon(icon);
end;
Avatar of Bobcsi

ASKER

I think, the problem: I load an icon (size: 64 x 64) into Ticon, but after it, i get the TIcon.Width and this value is 32. But Why?

And ImageList accept only 64x64 icon

Idea?:(

Bobcsi
Do you REALLY need the image in the ImageList to be an ICON? Can't it be just a bitmap?
Avatar of Bobcsi

ASKER

If i use a bitmap(64x64) i will get a ugly image.(bad shadow...etc)

Bobcsi