I have a icon which has a few different sizes (16px, 32px, 64px). I am calling ToBitmap()
on it, but it is always returning the 32px image. How do I retrieve the 64px one?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
This is a fairly painful limitation in the ResourceManager class. Its GetObject() method doesn't provide a way to pass extra arguments that would allow selecting the returned icon by size. A workaround is to add the icon to the project instead. Use Project + Add Existing Item, select your .ico file. Select the added icon and change the Build Action property to "Embedded Resource".
You can now retrieve the desired icon with code like this:
Sample usage:
Beware one possible failure mode: this code assumes that the icon was added to the same assembly that contains the method.
For anyone else stumbling upon the same problem, I've found a nice little solution.
Does this help?
The following sets the icon size for all the buttons in the toolbar.
It relies on the resource name being stored in the button tag.
There is no built-in method in the .Net framework that does this.
Instead, you can use this library.