Icon Chalange

  • Thread starter Thread starter K
  • Start date Start date
K

K

Dim img As New Bitmap(PictureBox1.Image, 32, 32)
img.Save(RichTextBox2.Text & "\" & RichTextBox3.Text & ".ico",
System.Drawing.Imaging.ImageFormat.Bmp)
MsgBox("Image has been converted", MsgBoxStyle.Information, "Done!")

Hi all, I am using Visual Basic 2008. The above code saves
PictureBox1 image into 32 x 32 icon file. The only problem I am facing
that when I chose this icon file from the Properties of my Form as for
Form icon in Visual Basic 2008 I get error message saying "Argument
'picture' must be a picture that can be used as a Icon". If I use same
icon file from the Properties of Active X Control Button which is on
excel Sheet then it works fine. I think if a icon file which can work
on Visual Basic Form and as well as on Active X Control Button on an
excel Sheet is the perfect icon. i tried different methods by
searching on internet to create perfect 16 x 16 or 32 x 32 icon files
which have no lost of colour or quality but only whith above code i
get near to what i want to achive. But i cant use it for my Visual
Basic application Form. I have created icon with below code which
works everywhere but with below code you lose the quality and colors
of the icon. I also studied "IconLib" example which you can find on
internet but its to much for me. So i am kind of stuck. Is there any
friend out there to help me out with some code.

Dim pth As String = "C:\Document\test.gif"
Dim img As New Bitmap(pth)
Dim grh As Graphics = Graphics.FromImage(img)
grh.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
grh.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("C\Document\test.ico",
IO.FileMode.Create)
newicon.Save(fpth)
newicon.Dispose()
MsgBox("Image has been converted", MsgBoxStyle.Information, "Done!")
 
Am 08.06.2010 15:35, schrieb K:
Dim img As New Bitmap(PictureBox1.Image, 32, 32)
img.Save(RichTextBox2.Text & "\" & RichTextBox3.Text & ".ico",
System.Drawing.Imaging.ImageFormat.Bmp)
MsgBox("Image has been converted", MsgBoxStyle.Information, "Done!")

Hi all, I am using Visual Basic 2008. The above code saves
PictureBox1 image into 32 x 32 icon file.

If you specify ImageFormat.Bmp it's a bitmap file, not an icon file.

The only problem I am facing
that when I chose this icon file from the Properties of my Form as for
Form icon in Visual Basic 2008 I get error message saying "Argument
'picture' must be a picture that can be used as a Icon". If I use same
icon file from the Properties of Active X Control Button which is on
excel Sheet then it works fine. I think if a icon file which can work
on Visual Basic Form and as well as on Active X Control Button on an
excel Sheet is the perfect icon. i tried different methods by
searching on internet to create perfect 16 x 16 or 32 x 32 icon files
which have no lost of colour or quality but only whith above code i
get near to what i want to achive. But i cant use it for my Visual
Basic application Form. I have created icon with below code which
works everywhere but with below code you lose the quality and colors
of the icon. I also studied "IconLib" example which you can find on
internet but its to much for me. So i am kind of stuck. Is there any
friend out there to help me out with some code.

Dim pth As String = "C:\Document\test.gif"
Dim img As New Bitmap(pth)
Dim grh As Graphics = Graphics.FromImage(img)
grh.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
grh.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("C\Document\test.ico",
IO.FileMode.Create)
newicon.Save(fpth)
newicon.Dispose()
MsgBox("Image has been converted", MsgBoxStyle.Information, "Done!")


I've now also spent some time to create an acceptable icon. I've also tried
the Image.GetThumbnailImage' function. Tried different pixel formats. All
without success.

The problem seems to be the icon.Save function because, if you call

newicon.ToBitmap

and save the resulting bitmap, the bitmap quality is much better. This
prooves that the icon quality is better than saved to file (otherwise
the bitmap created from the icon would be much worse).


..... This seems to be more helpful (look at the first reply):
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/341eb43e-5928-4ff5-813d-f5ea52411773
After all it gives a reason.
 
Back
Top