我正在尝试将位图保存为 ico 文件格式,但结果文件是扩展名为“ico”的 PNG 图像。
如果我选择图标格式,为什么 ImageFormat 类将我的位图保存为 PNG 格式?然后如何保存ico文件?
PS:我需要透明保存ICO
这就是我调用proc的方式:
Save_Icon(Resize_Image(Bitmap.FromFile(PictureBox_Regedit.Tag), 24, 24), "Regedit.ico")
这是代码的资源
Private Sub Save_Icon(ByVal Source As Bitmap, ByVal Filename As String)
Try
If Not Directory.Exists(AppDir) Then Directory.CreateDirectory(AppDir)
If Not Directory.Exists(AppIcons) Then Directory.CreateDirectory(AppIcons)
Source.MakeTransparent()
Source.Save(Path.Combine(AppIcons, Filename), ImageFormat.Icon)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
Private Function Resize_Image(ByVal img As Image, ByVal Width As Int32, ByVal Height As Int32) As Bitmap
Dim Bitmap_Source As New Bitmap(img)
Dim Bitmap_Dest As New Bitmap(CInt(Width), CInt(Height))
Dim Graphic As Graphics = Graphics.FromImage(Bitmap_Dest)
Graphic.DrawImage(Bitmap_Source, 0, 0, Bitmap_Dest.Width + 1, Bitmap_Dest.Height + 1)
Return Bitmap_Dest
End Function