Icon problems

ilyail3

Active member
Joined
Feb 15, 2005
Messages
31
Programming Experience
1-3
I have a problem saving imported icons the import code is:
VB.NET:
	Friend icon() As System.Drawing.Icon
#Region "API"
	Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
				(ByVal lpszFile As String, _
				 ByVal nIconIndex As Integer, _
				 ByRef phiconLarge As Integer, _
				 ByRef phiconSmall As Integer, _
				 ByVal nIcons As Long) As Integer
	Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Integer, ByVal lpszExeFileName As String, ByVal nIconIndex As Integer) As Integer
#End Region
	Friend Function GetNumberOfIcons(ByVal fl As String) As Integer
		Return ExtractIconEx(fl, -1, 0, 0, 0)
	End Function
	Friend Sub LoadIconFile(ByVal URL As String)
		Dim numicons As Integer  ' number of regular icons in the file
		Dim retval As Integer  ' return value
		numicons = GetNumberOfIcons(URL)
		ReDim icon(numicons - 1)
		For i As Integer = 0 To numicons - 1
			Dim newform As New Form
		    retval = ExtractIcon(newform.Handle.ToInt64, URL, i)  '?Me.Handle?
			If retval > 0 Then
				Dim stream As New IO.MemoryStream
			 icon(i) = System.Drawing.Icon.FromHandle(New IntPtr(retval))
				Application.DoEvents()
			End If
		Next
	End Sub
But when I try to save it using this code:
VB.NET:
Friend Function save_icon(ByVal icon_index As Integer) As String
		Dim icondir As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\icons\icon"
		Dim i As Integer = 1
		Do Until compare_with_file(icon_index, icondir & i & ".ico") = True Or System.IO.File.Exists(icondir & i & ".ico") = False
			i += 1
		Loop
		If System.IO.File.Exists(icondir & i & ".ico") = False Then
			Dim steam As New System.IO.MemoryStream
			icon(icon_index).Save(steam)
			Dim b(steam.Length) As Byte
			steam.Position = 0
			steam.Read(b, 0, steam.Length)
			steam.Close()
			Dim strIcon As New IO.FileStream(icondir & i & ".ico", IO.FileMode.CreateNew)
			strIcon.Write(b, 0, b.Length)
			strIcon.Close()
		End If
		save_icon = icondir & i & ".ico"
	End Function
the icon saves using low resolution and low colors
 
Last edited:
Back
Top