NoCoolHandle
Programmer
Hi,
Does anyone know how to save an Icon to a .ico file without loosing too much quality.
I have some code that allows me to read a bitmap into an icon class object and apply it to a form. The quality when displayed in a form is excellent. However trying to export it as an external icon renders a very low quality image, and binding it back to a different form is equally bad.
What I have tried is using the icons save method. This allows for a stream object as an argument, but the resulting stream when saved to a file looks nothing like what is being displayed in the form.
Code to build icon from file..
Does anyone know how to save an Icon to a .ico file without loosing too much quality.
I have some code that allows me to read a bitmap into an icon class object and apply it to a form. The quality when displayed in a form is excellent. However trying to export it as an external icon renders a very low quality image, and binding it back to a different form is equally bad.
What I have tried is using the icons save method. This allows for a stream object as an argument, but the resulting stream when saved to a file looks nothing like what is being displayed in the form.
Code to build icon from file..
Code:
Private Sub BindImageAsIcon(ByVal sender As Object, ByVal e As Windows.Forms.PaintEventArgs) Handles Me.Paint
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("C:\cam.png")
' Get an Hicon for myBitmap.
Dim HIcon As IntPtr = myBitmap.GetHicon()
' Create a new icon from the handle.
Dim newIcon As Icon = System.Drawing.Icon.FromHandle(HIcon)
' Set the form Icon attribute to the new icon.
Me.Icon = newIcon
End Sub