我試圖將位圖保存爲ico文件格式,但結果文件是擴展名更改爲「ico」的PNG圖像。將位圖保存爲ICO文件,具有透明度
爲什麼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
經過在谷歌大量研究有關如何在.NET中使用lib你是對的FreeImage是最好的方式嘿嘿,謝謝 – ElektroStudios
只有一件事,我不能打開並編譯針對64位proyects(anycpu或x64配置)的源代碼,也許請你可以鏈接已編譯的freeimage dll for anycpu和x64,如下所示?:http://www.sambeauvois.be/blog/2010/05/freeimage-and-x64-projects-yes-you-can/ – ElektroStudios
我自己編譯了一個64位版本,但我添加並更改了一些內容,它是2010版本。 – Alexander