脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

winfrom手动选择文件完整路径

2579人阅读 2021/12/23 11:58 总访问:645047 评论:0 收藏:0 手机
分类: 文件流

前言

笔记

具体代码

       // 选择路径
        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);


评价