From: K on
Hi all, I have vb code below which convert image to icon but there
are two problem with this. One when i try to save 16 x 16 size icons,
it creates black bacground whith that icon. Two it saves 32 x 32 icon
ok but in different colours from the original image colours. I'll be
very greateful if any friend has sultion for this.


Dim img As New Bitmap(PictureBox1.Image, 32, 32)
Dim g As Graphics = Graphics.FromImage(img)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(img, 0, 0)
Dim Hicon As IntPtr = img.GetHicon
Dim newicon As Icon = System.Drawing.Icon.FromHandle(Hicon)
Dim fpth As New IO.FileStream(RichTextBox2.Text & "\" &
RichTextBox3.Text & ".ico", IO.FileMode.Create)
newicon.Save(fpth)
newicon.Dispose()
MsgBox("Image has been converted", MsgBoxStyle.Information, "Done!")
From: Herfried K. Wagner [MVP] on
Am 28.02.2010 10:59, schrieb K:
> Hi all, I have vb code below which convert image to icon but there
> are two problem with this. One when i try to save 16 x 16 size icons,
> it creates black bacground whith that icon. Two it saves 32 x 32 icon
> ok but in different colours from the original image colours.

You may want to use this library (untested):

IconLib - Icons Unfolded (MultiIcon and Windows Vista supported) -
CodeProject
<URL:http://www.codeproject.com/KB/cs/IconLib.aspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>