zoukankan      html  css  js  c++  java
  • 将图片进行base64编码,并将接受编码后的图片转换为实际图片

     

    /// <summary>
    /// Baser64Code 的摘要说明。
    /// </summary>
    public class Baser64Code
    {
       /// <summary>
       /// 编码的静态方法
       /// </summary>
       /// <param name="filepath"></param>
       /// <returns>编码后的字符串</returns>
       public static string ConvertBase64(string filepath)
       {  
        //变量
        string result = string.Empty;

        //将文件转换为stream
        using(FileStream fs = new FileStream(filepath,FileMode.Open))
        {
         byte[] buffer = new byte[fs.Length];
         fs.Read(buffer,0,buffer.Length);
         result = Convert.ToBase64String(buffer); //base64编码
        }

        //返回编码后的字符串
        return result;
       }

       /// <summary>
       /// 解码的静态方法
       /// </summary>
       /// <param name="strBase64"></param>
       /// <returns>保存路径</returns>
       public static string FromBase64(string strBase64)
       {
        //存放图片的路径
        string imgPath = @"F:\1.gif";

        //将base64编码存入byte字节
        byte[] buffer = Convert.FromBase64String(strBase64);
        FileStream fs = new FileStream(imgPath,FileMode.Create);
        //将字节写入图片
        fs.Write(buffer,0,buffer.Length);    

        //返回路径
        return imgPath;
       }

  • 相关阅读:
    busybox 注意事项
    Implicit vs Explicit Sharing
    Font Creator Program 字库修改合并软件
    Iperf 源代码分析(四)
    QML 中文支持
    file operation
    MFC异常 与C++标准异常
    统一建模语言(UML) 版本 2.0
    MultiByteToWideChar和WideCharToMultiByte用法详解
    UML 基础: 类图
  • 原文地址:https://www.cnblogs.com/dudu837/p/1397060.html
Copyright © 2011-2022 走看看