C# 图片的读取

 

 

        //图片转成二进制
        public byte[] GetPictureData(string imagepath)
        {
            /**/
            ////根据图片文件的路径使用文件流打开,并保存为byte[] 
            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 listbit = new List();
            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;
        }

 

你可能感兴趣的:(halcon,C#,视觉)