• 图片与base64的互转


     /// <summary>
            /// 把图片转换到文本信息
            /// </summary>
            /// <param name="imagePath">图片的路径</param>
            /// <param name="savePath">文本存储路径</param> 

    public void GetImageToString(string imagePath,string savePath)
            {
                Stream s = File.Open(imagePath, FileMode.Open);
                int leng = 0;
                if (s.Length < Int32.MaxValue)     //防止图片太大了
                leng = (int)s.Length;
                byte[] by = new byte[leng];        //声明字节数组

                MemoryStream s = new MemoryStream(by);    //内存中声明一个流       
                s.Read(by, 0, (int)s.Length);//把图片读到字节数组中
                s.Close();

                string str = Convert.ToBase64String(by);//把字节数组转换成字符串
                StreamWriter sw = File.CreateText(savePath);//存入savePath文件
                sw.Write(str);
                sw.Close();
                sw.Dispose();
            }

             /// <summary>
            /// 把字符串还原成图片
            /// </summary>
            /// <param name="path"></param>
            /// <returns>图片</returns>

            public Image GetImageFromString(string stringPath)
            {
                StreamReader sr = new StreamReader(stringPath);
                string s = sr.ReadToEnd();
                sr.Close();
                byte[] buf = Convert.FromBase64String(s);//把字符串读到字节数组中

                MemoryStream ms = new MemoryStream(buf);
                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
                img.Save("12.gif", System.Drawing.Imaging.ImageFormat.Gif);  //保存成图片
                ms.Close();
                ms.Dispose();
                return img;
            }

  • 相关阅读:
    双色球的概率和收益
    伽玛函数
    概率统计13——二项分布与多项分布
    贝叶斯决策理论(1)
    线性代数笔记34——左右逆和伪逆
    线性代数笔记33——基变换和图像压缩
    线性代数笔记32——线性变换及对应矩阵
    线性代数笔记31——奇异值分解
    线性代数笔记30——相似矩阵和诺尔当型
    线性代数笔记29——正定矩阵和最小值
  • 原文地址:https://www.cnblogs.com/hongsedigua/p/3790404.html
Copyright © 2020-2023  润新知