32-Bit Icon to Bitmap?

Menge

Well-known member
Joined
Jul 3, 2003
Messages
108
Location
Recife - PE - Brazil
hi guys!

im posting here because i really couldnt find anywhere else on the net a way to create a bitmap from a 32bit icon.

no matter what i do i ALWAYS get a icon with a black border (if it uses alpha)

heres what im doing.

Code:
DockTypes.SHFileInfo FileInfo=new DockTypes.SHFileInfo();
SHGetFileInfo(ItemPath, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), 0x200 | 0x100 | 0x0);
Icon ItemIcon=Icon.FromHandle(FileInfo.hIcon);
Bitmap IconBitmap=ItemIcon.ToBitmap();

and no matter what i do, it just saturates the alpha channel as if it were 1-bit. All i need is just a bitmap of the icon. nothing more.

can anyone please help?
 
Im afraid youll have to keep it in Icon format and draw it using DrawIcon(). Theres a bug in .NET where the alpha channel on 32bit icons is not preserved, as you have discovered. If you are adding this in to an image list, add the icon straight in to it (no intermediate bitmap), make sure the image list has the correct colour depth and make sure your application has a manifest to use common controls 6.
 
i really need this on Bitmap format b/c i need to create a Direct3DTexture out of this... dang... i even tried this

Code:
ItemIcon=Icon.FromHandle(FileInfo.hIcon);
Bitmap IconPic=new Bitmap(128,128);
Graphics g=Graphics.FromImage((Bitmap)IconPic);
g.DrawIcon(ItemIcon, new Rectangle(new Point(0,0),new Size(128,128)));
g.Dispose();

and EVEN SO it gets black borders around it... dang... any help?
 
I got the same problem....

Use like divil says, the DrawIcon method to Draw an item...


I have designed the IconBox control... see NicoLibrary on this forum...


Nico
 
Why do you need to put an icon in Direct3D? You could create the texture from the Bitmap and use a transparency key to remove the background if its all the same color
 
its for a program which im making.

its a laucher program. but im adding more features to it.
the thing is. i have an Item type which is an alias to a folder on the hard drive... so clicking this item makes my program open the folder and display its contents. and for its UI, im using Direct3D. i find it very cool :)

u can get an internal preview here

AndreRyan, transparency keys doesnt work on XP-styled icons... thats where im having problems... on icons with an 8-bit alpha channel. usual 1-bit alpha channelled icons display just great :)
 
This may be useless because itll probably have the same effect but you can make Bitmaps directly from hIcons
C#:
DockTypes.SHFileInfo FileInfo=new DockTypes.SHFileInfo();
SHGetFileInfo(ItemPath, 0, ref FileInfo, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FileInfo), 0x200 | 0x100 | 0x0);
Bitmap IconBitmap=Bitmap.FromHicon(FileInfo.hIcon);
 
Back
Top