Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hi guys!

 

i'm posting here because i really couldn't 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)

 

here's what i'm doing.

 

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?

Menge
  • *Gurus*
Posted
I'm afraid you'll have to keep it in Icon format and draw it using DrawIcon(). There's 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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

i really need this on Bitmap format b/c i need to create a Direct3DTexture out of this... dang... i even tried this

 

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?

Menge
Posted
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 it's all the same color
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

it's for a program which i'm making.

 

its a laucher program. but i'm 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, i'm using Direct3D. i find it very cool :)

 

u can get an internal preview here

 

AndreRyan, transparency keys doesn't work on XP-styled icons... that's where i'm having problems... on icons with an 8-bit alpha channel. usual 1-bit alpha channelled icons display just great :)

Menge
Posted

This may be useless because it'll probably have the same effect but you can make Bitmaps directly from hIcons

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);

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...