排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
文件流
前言
笔记
具体代码
// 选择路径 private string SelectPath() { string path = string.Empty; OpenFileDialog openFileDialo = new OpenFileDialog(); openFileDialo.Filter = "所有文件(*.*)|*.*"; if (openFileDialo.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = openFileDialo.FileName; } return path; } //图片转成二进制 public byte[] GetPictureData(string imagepath) { /**/ FileStream FileStream = new FileStream(imagepath, FileMode.Open); byte[] byData = new byte[FileStream.Length]; FileStream.Read(byData, 0, byData.Length); FileStream.Close(); return byData; } //二进制转图片 public Image ReturnPhoto(string imagepath) { List<byte> listbit = new List<byte>(); listbit.AddRange(GetPictureData(imagepath)); byte[] bit = listbit.ToArray(); System.IO.MemoryStream ms = new System.IO.MemoryStream(bit); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); return img; }
调用就行了
string fliepath = SelectPath(); Image image = ReturnPhoto(fliepath);
评价