ICO to GIF? (transparant)

E

Edwin Knoppert

I'm trying to convert an icon handle to GIF.

Something like:
Public Function GetImageFromIconHandle(ByVal hIcon As Int32) As Int32
Dim ico As Icon = Icon.FromHandle(hIcon)
Dim x As New Drawing.IconConverter
'x.ConvertTo(ico,typeof(System.Drawing.Imaging.ImageFormat.Gif) )
End Function

x.ConvertTo(ico, <requires a system.type> )

I don't know how to do that.
Important is that a transparent icon should remain transparent.

hIcon is a valid 16x16 icon.
 
E

Edwin Knoppert

That would not work but..

i already converted to bmp and i used that code.
But the backcolor remains black while i added:
Dim bmp As Bitmap = ico.ToBitmap
bmp.MakeTransparent(Color.Black)
Return bmp

The image remains the same though.
Better see a real example with a transparent ico > gif.

Your suggestion:
For the type i used: x.ConvertTo(ico, bmp.GetType)
But i don't know what to use to draw to user, and even to expect a
transparent gif since i still use a bitmap object (GIF is bitmap so i should
give it a chance).

Currently the BMP is shown:
Response.ContentType = "image/gif"
Dim xx As System.Drawing.Imaging.ImageFormat
' send the image to the viewer
bmp.Save(Response.OutputStream, xx.Gif)

bmp.Dispose()
Response.End()
 
N

Nathan Sokalski

Making an image transparent in .NET is a rather complicated process, which I
don't quite understand. Here is a page that I was referred to by someone in
a newsgroup which is supposed to work. It is written in C#. I am a VB.NET
coder, and I couldn't get it to work in that, but I think that is due to the
unmanaged code capabilities of C#. I have not tried the code in C#, so I am
assuming it would work if I did it in C#. See what it does for you. (If you
do figure out a way to get it to work in VB.NET, could you let me know?)
Here is the URL:

http://ewbi.blogs.com/develops/2005/08/sparklines_22.html

Good Luck!
 
E

Edwin Knoppert

Thanks, will take a peek tomorrow :)

It's a bit odd though, both types support tranparancy.
So some conversion unit could 'know' what get's transparent (imo).
Conversion to plain BMP first is prob.not ok.
However dotnet has a maketransparent method, and i was hoping this would
work at least.
I did not see any difference.

But hey.. what do i know? :)
 
N

Nathan Sokalski

Don't let that make you feel too bad, my first attempt at transparency was
to use the MakeTransparent method, too. To be honest, I think that there
should be a method (or maybe a predefined Color, or maybe a separate class
that inherits something from GDI+ that is used for making transparent
images) that makes it simpler. Maybe if we're lucky that make one in a
future release of .NET, because if you think about it, transparency is used
in almost all gif images, I mean, when was the last time you saw a button or
logo that was completely rectangular?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top