• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

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
0
Bobcsi
Asked:
Bobcsi
  • 7
  • 5
1 Solution
 
vaceroseCommented:
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.

0
 
Eddie ShipmanAll-around developerCommented:
From MSDN:
"Note  This function hase been superseded by the LoadImage function."

var
 hi: TIcon;
begin
 hi := TIcon.Create;
 try
   hi.Handle := LoadImage(hInst, MakeIntResource(ICON_NAME), IMAGE_ICON, 64, 64, LR_DEFAULTCOLOR);
   // Assign it...
 finally
   hi.Free;
 end;
end;
0
 
BobcsiAuthor Commented:
Thx

Fast answer

Solution:

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

Bobcsi
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BobcsiAuthor Commented:
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
0
 
Eddie ShipmanAll-around developerCommented:
Please post your icon somewhere where I can download it. I can not create a 64x64 icon using the tools I have.
0
 
BobcsiAuthor Commented:
0
 
BobcsiAuthor Commented:
0
 
Eddie ShipmanAll-around developerCommented:
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
0
 
BobcsiAuthor Commented:
ok, posted.
0
 
Eddie ShipmanAll-around developerCommented:
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;
0
 
BobcsiAuthor Commented:
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
0
 
Eddie ShipmanAll-around developerCommented:
Do you REALLY need the image in the ImageList to be an ICON? Can't it be just a bitmap?
0
 
BobcsiAuthor Commented:
If i use a bitmap(64x64) i will get a ugly image.(bad shadow...etc)

Bobcsi
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now