Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Icon to .ico Q.

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
US
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..
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top