Session

winfrom手动选择文件完整路径

电脑版发表于:2021/12/23 11:58

前言

笔记

具体代码

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


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢