Csharp/C#教程:将图像从资源文件保存到计算机 – c#分享


将图像从资源文件保存到计算机 – c#

Okei,我有一个带有资源文件的C#项目。 资源文件包含图像(.png)。 我希望将png文件保存/解压缩到我的计算机上的指定文件夹中。 我该怎么做呢?

static void ExtractFileResource(string resource_name, string file_name) { try { if (File.Exists(file_name)) File.Delete(file_name); if (!Directory.Exists(Path.GetDirectoryName(file_name))) Directory.CreateDirectory(Path.GetDirectoryName(file_name)); using (Stream sfile = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource_name)) { byte[] buf = new byte[sfile.Length]; sfile.Read(buf, 0, Convert.ToInt32(sfile.Length)); using (FileStream fs = File.Create(file_name)) { fs.Write(buf, 0, Convert.ToInt32(sfile.Length)); fs.Close(); } } } catch (Exception ex) { throw new Exception(string.Format("Can't extract resource '{0}' to file '{1}': {2}", resource_name, file_name, ex.Message), ex); } } 

看到这个页面它可以帮助: MSDN保存图像

你有没有尝试过:

从组件或组件中提取嵌入式图像

如何灿我提取物-一个文件从-一个嵌入资源并节省,它到磁盘

这个?

上述就是C#学习教程:将图像从资源文件保存到计算机 – c#分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/959655.html

(0)
上一篇 2021年11月23日
下一篇 2021年11月23日

精彩推荐