保存位图ICO文件,具有透明度 [英] Save Bitmap to ICO file, with transparency
问题描述
我试图挽救一个位图到ICO文件格式,但结果文件是扩展PNG图像改为ICO。
为什么的imageformat类是救了我的位图PNG格式,如果我选用图标格式?再怎么保存ICO文件?
PS:我需要保存ICO透明
这是我如何调用PROC:
Save_Icon(Resize_Image(Bitmap.FromFile(PictureBox_Regedit.Tag),24,24),Regedit.ico)
这是code的RES
私人小组Save_Icon(BYVAL来源为位图,BYVAL文件名作为字符串) 尝试
如果不Directory.Exists(APPDIR)然后Directory.CreateDirectory(APPDIR)
如果不Directory.Exists(AppIcons)然后Directory.CreateDirectory(AppIcons)
Source.MakeTransparent()
Source.Save(Path.Combine(AppIcons,文件名),ImageFormat.Icon)
抓住EX为例外
抛出新的异常(ex.Message)
结束Try结束小组专用功能Resize_Image(BYVAL IMG作为图像,BYVAL宽度的Int32,BYVAL高度的Int32)为位图
昏暗Bitmap_Source作为新位图(IMG)
昏暗Bitmap_Dest作为新位图(CINT(宽),CINT(高))
昏暗的图形作为图形= Graphics.FromImage(Bitmap_Dest)
Graphic.DrawImage(Bitmap_Source,0,0,Bitmap_Dest.Width + 1,Bitmap_Dest.Height + 1)的
返回Bitmap_Dest
结束功能
另存为,在编辑应用程序总是意味着转换,这你是不是在这里做什么。
例如,您可以使用 Bitmap.GetHicon方法您的源转换为图标的格式,并使用的 System.Drawing中图标类从那里的。不要忘了破坏惠康
之后。
问题是,如果我没有记错,这就是.NET框架离开你。我不记得透明度的功能,我已经在几年前切换到的FreeImage 库,全力以赴与至今。
I'm trying to save a bitmap to a ico file format, but the result file is a PNG image with the extension changed to "ico".
Why the ImageFormat Class is saving my Bitmap as PNG format if I choosed Icon format? and then how to save the ico file?
PS: I need to save the ICO with transparency
This is how I call the proc:
Save_Icon(Resize_Image(Bitmap.FromFile(PictureBox_Regedit.Tag), 24, 24), "Regedit.ico")
And this is the res of the code
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
"Save As" in editing applications always implies conversion, which you are not doing here.
You can for example use the Bitmap.GetHicon Method to convert your source to an icon format, and use the System.Drawing Icon Class from there. Don't forget to destroy the Hicon
after that.
Problem is, if I remember correctly, that's where the .NET Framework leaves you. I cannot recall transparency functionality, and I've switched to the FreeImage library a couple of years ago, and do everything with that since.
这篇关于保存位图ICO文件,具有透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!