【美高梅开户网址】字符数组或字符串的长短无效等难点化解方案

类型极度须求,调用ActiveX三个维度控件实行控件某一杰出地位的截图操作,那个截图保存由ActiveX控件调节保存到本地是没难题的,以往急需将这么些截图上传出服务器,四个人共享,就推来推去到必要读取当半夏件……后联络后,ActiveX控件方提供1个接口,再次来到相关截图像和文字件的Base6四编码字符串,由Web应用程序调换为对应格式,存款和储蓄在服务器就可以。

Base-64 字符数组或字符串的长度无效等主题素材一挥而就方案,base-64数组

品种尤其供给,调用ActiveX三维控件进行控件某一特有地点的截图操作,那么些截图保存由ActiveX控件调整保存到本地是没难点的,今后亟需将以此截图上传到服务器,五个人共享,就牵涉到必要读取当麻芋果件……后联络后,ActiveX控件方提供三个接口,再次来到相关截图像和文字件的Base64编码字符串,由Web应用程序调换为对应格式,存款和储蓄在服务器就能够。

遇上难点:

Base-64 字符数组或字符串的长短无效

一直调用Convert.FromBase64String方法时,报“Base-6四字符数组或字符串的长短无效”的错误。

MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));

于是想到对ActiveX重临的Base64字符串举办编码操作

base64 = System.Web.HttpUtility.HtmlEncode(base64);

MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));

运作程序,报“输入的不是行得通的 Base-6四 字符串,因为它涵盖非 Base-64字符、四个以上的填充字符,也许填充字符间包罗违法字符”错误。

末尾化解方案:

对Base6四字符串实行特殊字符替换,并拓展PadRight操作,消除难题

string dummyData = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
if (dummyData.Length % 4 > 0)
{
    dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
}
MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));

末段提供一下卷入的Base64Helper类,提供Base6肆字符串与公事之间互相调换操作。

/// <summary>
    /// Base64编码字符串与文件转换帮助泪
    /// </summary>
    public class Base64Helper
    {
        /// <summary>
        /// Base64编码字符串转文件
        /// </summary>
        /// <param name="base64">Base64编码字符串</param>
        /// <param name="filename">文件完整路径</param>
        public static void ConvertBase64ToFile(string base64, string filename)
        {
            //base64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDwP45/tRfE/wDZx+FumaR4Ug1u2u7Oe5nk1uw1e406WLM9hJ5qmF2hmYPZWjrklxMiSAs8Ubpg/sh+Opf2p/BWuad8Zvh5p0/hnSNHt9Pt/GlxZul9bXdoWktre3vg4Vm8t4kkaeOfbbWdpEBF5dtt77Uf2C/GPx2+IM/jr4q61e+GtJkDLDo0V3Ffai/zTYLSl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im().Replace("%", "").Replace(",", "").Replace(" ", "+");
            if (dummyData.Length % 4 > 0)
            {
                dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
            }
            MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));
            //filename = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            Bitmap img = new Bitmap(stream);
            img.Save(filename);
        }

        /// <summary>
        /// 文件转Base64编码字符串
        /// </summary>
        /// <param name="fileName">文件完整路径</param>
        /// <returns></returns>
        public static string ConvertFileToBase64(string fileName)
        {
            //fileName = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            FileStream fs = File.OpenRead(fileName);
            BinaryReader br = new BinaryReader(fs);
            byte[] bt = br.ReadBytes(Convert.ToInt32(fs.Length));
            string base64String = Convert.ToBase64String(bt);
            return base64String;
        }
    }

字符数组或字符串的尺寸无效等主题材料一下子就解决了方案,base-6肆数组
项目卓越要求,调用ActiveX三个维度控件进行控件某一特别地方的截图操作,那…

品类越发要求,调用ActiveX三维控件举行控件某1特有地点的截图操作,这几个截图保存由ActiveX控件调节保存到地点是没难点的,今后亟待将以此截图上盛传服务器,五人共享,就牵涉到须要读取当半夏件……后关系后,ActiveX控件方提供三个接口,重返相关截图像和文字件的Base6四编码字符串,由Web应用程序转变为对应格式,存款和储蓄在服务器就可以。

眼下的话

  base-6四作为大规模的编码函数,在基本注脚、摘要认证以及部分HTTP扩大中获取了汪洋选用。在前者领域,也不时把图纸调换为base-64编码在互连网中传输。本文将详细介绍base6四的原理及用js落成base6肆编码器的历程

 

境遇难题:

遇见难题:

原理

  Base-64编码能够将轻松1组字节转变到较长的常见文本字符种类,从而得以合法地作为首部字段值。Base-64编码将用户输入或二进制数据,打包成一种安全格式,将其看作HTTP首部字段的值发送出去,而无须思念里面包罗会损坏HTTP分析程序的冒号、换行符或二进制值

  Base-6四编码是用作MIME多媒体电子邮件标准的一有个别支出的,那样MIME就可以在区别的法定电子邮件网关之间传输富文本和自由的2进制数据了。Base-64编码与将2进制数据文本化表示的uuencode和BinHex规范在精神上很周围,但空间功能更加高

【拆分】

  Base-6四编码将四个5人字节种类拆散为八位的有些,并为各样5位的有的分配两个字符,这些字符是Base-6四字母表中的陆十一个字符之1。那6二十个出口字符都是很宽泛的,能够安枕而卧地坐落HTTP首部字段中。那6二个字符中富含大小写字母、数字、+和/,还选取了特殊字符=

下表Base-6四的字母表

美高梅开户网址 1【美高梅开户网址】字符数组或字符串的长短无效等难点化解方案。;)

0   A   8    I   16   Q   24   Y   32   g   40   o   48   w   56   4
1    B    9     J    17    R    25    Z    33    h    41    p    49    x    57    5
2    C    10    K    18    S    26    a    34    i    42    q    50    y    58    6
3    D    11    L    19    T    27    b    35    j    43    r    51    z    59    7
4    E    12    M    20    U    28    c    36    k    44    s    52    0    60    8
5    F    13    N    21    V    29    d    37    l    45    t    53    1    61    9
6    G    14    O    22    W    30    e    38    m    46    u    54    2    62    +
7    H    15    P    23    X    31    f    39    n    47    v    55    3    63    /

美高梅开户网址 2😉

  [注意]由于Base6四编码用七位字符表示信息中的几个位,所以Base-6肆编码字符串大致比原始值扩张了
3叁%

【编码完毕】

  下图是三个粗略的Base-64编码实例。在那边,四个字符组成的输入值“Ow!”是Base-6四编码的,获得的是五个字符的Base-6四编码值“T3ch”。它是按以下办法行事的

美高梅开户网址 3

  1、字符串“Ow!”被拆分成1个六人的字节(0x四F、0x7七、0x21)

  贰、那一个字节构成了3个二十四人的2进制值0拾0111十111011100一千0一

  三、这几个位被划分为局地五个人的连串0十01一、1拾111、011十、一千0一

  四、各类5位值都表示了从0-陆叁里面的三个数字,对应Base-6四字母表中陆10个字符之壹。获得的Base-64编码字符串是个肆字符的字符串“T三ch”,然后就能够通过线路将以此字符串作为“安全的”八位字符传送出来,因为只用了有的
移植性最佳的字符(字母、数字等)

【填充】

  Base-6四编码收到三个五位字节种类,将以此二进制体系流划分成7位的块。2进制类别有时无法正好平均地分为8人的块,在那种状态下,就在系列末尾填充零位,使2进制连串的尺寸成为24的翻番(陆和捌的最小公倍数)

  对已填写的贰进制串举办编码时,任何完全填充(不包涵原始数据中的位)的陆位组都由新鲜的第伍五个标识“=”表示。假如5个人组是有的填充的,就将填充位设置为0

  下表展现了有个别填写实例

美高梅开户网址 4

  伊始输入字符串“a:a”为3字节(2多少人)。2四是六和8的翻番,因而无需填充,获得的Base-6四编码字符串为“YTph”

  可是,再扩大三个字符,输入字符串会成为311个人长。而六和捌的下贰个翻番是4八,由此要增进18人的填充码。填充的前四位是与数量位混合在协同的。获得的5个人组0一xxxx,会被当作0一千0、十进制中的1陆,大概Base-6肆编码的Q来管理。剩下的七个6人组都以填充码,用“=”表示

  [美高梅开户网址,注意]Base-6四编码的法定正式移动至此

Base-64 字符数组或字符串的长短无效

Base-6四 字符数组或字符串的长短无效

应用

  网页上的每一个图纸,都急需开销3个http请求下载而来的。所以,才有了雪碧图技术

  无论如何,图片的下载始终都要向服务器发出请求,如若图片的下载不用向服务器发出请求,而得以随着HTML的下载同时下载到本地那就太好了,而base64正好能一蹴即至这么些标题

  前边提到过Base-6四编码字符串差不多比原始值扩张了33%。所以,不是享有的图纸选拔base-6四编码都合适

  但是,要是图片充裕小且因为用处的特殊性(如须要平铺等)无法被塑产生七喜图,在整个网站的复用性非常高且基本不会被更新。那么此时使用base64编码传输图片就可谓好钢用在刀刃上

  比如,三个唯有50字节的2px*贰px的背景图。将其转会成base6四编码,唯有十0两个字符,相比较二个http请求,那种转移无疑更值得重视

  把要转正的图形直接拖入chrome中,使用调节马尔默的Source选项,可直接查看图片的base6四编码

美高梅开户网址 5

直接调用Convert.FromBase6四String方法时,报“Base-64字符数组或字符串的长度无效”的错误。

直白调用Convert.FromBase6四String方法时,报“Base-6四字符数组或字符串的长短无效”的错误。

字符串编码

  对于字符串来说,在javaScript中,有1个函数分别用来处掌握码和编码base6四字符串:atob()和btoa()

  btoa()函数能够从二进制数据“字符串”创造1个base-6肆编码的ASCII字符串;相反地,atob()函数能够解码通过base-6四编码的字符串数据。

console.log(btoa('abc'));//'YWJj'
console.log(atob('YWJj'));//'abc'

  [注意]IE九-浏览器不协助

  可是,以上办法有局限性,便是无能为力调换汉语

Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

  那时,就要求利用编码方法,先转移为btoa()识其他字符,再举办base6四编码,如能够应用encodeUXC60I()方法

var str = btoa(encodeURI('小火柴'));
console.log(str);//JUU1JUIwJThGJUU3JTgxJUFCJUU2JTlGJUI0
console.log(decodeURI(atob(str)));//'小火柴'

美高梅开户网址 6😉

<p style="margin:0">请在下面的框中输入要转换的字符</p>
<textarea  id="ta" cols="30" rows="10"></textarea>
<button id="btn1">转换</button><button id="btn2">反向转换</button><br>
<p style="margin:0">转换后的字符如下:</p>
<textarea id="result" cols="30" rows="10" readonly></textarea>
<button id="sel">全选</button>
<button id="reset">清空</button>
<script>
reset.onclick = function(){history.go();}
btn1.onclick = function(){result.value = btoa(encodeURI(ta.value));}
btn2.onclick = function(){result.value = decodeURI(atob(ta.value));}
sel.onclick = function(){
    result.focus();
    result.select();
}
</script>

美高梅开户网址 7😉

 

MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));
MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));

图表编码

  使用文件File
API的readAsDataULacrosseL()方法,能够将文件以多少U奥迪Q3I(进行Base6四编码)格局保留在result属性中

美高梅开户网址 8😉

//base64转换函数
function base64(file){
    if(fileData.innerHTML){
        fileData.innerHTML = '';
        btn.style.display = 'none';
    }
    if(file){
        if(/image/.test(file.type)){
          var reader = new FileReader();
          reader.readAsDataURL(file);
          reader.onload = function(){
              fileData.innerHTML = reader.result;
          }          
        }else{
          alert("You must select a valid image file!");
        }
    }    
}

美高梅开户网址 9😉

  一般地,生成的Base64编码都相比较长,能够扩展3个全选代码的作用

美高梅开户网址 10😉

reader.onload = function(){
    fileData.innerHTML = reader.result;
    btn.style.display = 'inline-block';
    btn.onclick = function(){
        fileData.focus();    
        fileData.select();
   }
}     

美高梅开户网址 11😉

  可以选用文件File API选拔图片文件

美高梅开户网址 12😉

//点击事件替代
targetArea.onclick = function(){file1.click();}
//控件选中
file1.onchange = function(){
    var file = file1.files[0];
    base64(file);    
}

美高梅开户网址 13😉

  当然也能够利用原生拖拽,完成图片拖拽,在某些区域显示Base64编码的作用

美高梅开户网址 14😉

targetArea.ondragenter = function(e){this.style.outline = "1px solid black";}
targetArea.ondragleave = function(e){this.style.outline = "";}
//拖拽选中
targetArea.ondrop = function(e){
    e = e || event;
    this.style.outline = "";
    var file = e.dataTransfer.files[0];
    base64(file);
}

美高梅开户网址 15😉

  由于File API的包容性限制,以下代码在IE玖-浏览器中不只怕符合规律运作

美高梅开户网址 16😉

<input id="file1" type="file" accept="image/gif,image/jpeg,image/jpg,image/png,image/x-icon"  style="display:none">
<div id="targetArea" style="display:inline-block;vertical-align:middle;height:100px;line-height:50px;width:210px;background:lightblue;">将图片文件拖放到该区域内<br>或者点击该区域选择本地文件</div>
<textarea id="fileData" style="vertical-align:middle;width:400px;height:200px;overflow:auto;word-wrap: break-word;"></textarea>
<button id="btn" style="display:none;position:absolute;margin:220px 0 0 -80px">全选代码</button>
<script>
//base64转换函数
function base64(file){
    if(fileData.innerHTML){
        fileData.innerHTML = '';
        btn.style.display = 'none';
    }
    if(file){
        if(/image/.test(file.type)){
          var reader = new FileReader();
          reader.readAsDataURL(file);
          reader.onload = function(){
              fileData.innerHTML = reader.result;
              btn.style.display = 'inline-block';
              btn.onclick = function(){
                  fileData.focus();    
                  fileData.select();
             }
          }          
        }else{
          alert("You must select a valid image file!");
        }
    }    
}
//点击事件替代
targetArea.onclick = function(){file1.click();}
//控件选中
file1.onchange = function(){
    var file = file1.files[0];
    base64(file);    
}
//兼容事件处理程序
function addEvent(target,type,handler){
    if(target.addEventListener){
        target.addEventListener(type,handler,false);
    }else{
        target.attachEvent('on'+type,function(event){
            return handler.call(target,event);
        });
    }
}
//兼容阻止默认事件
function preventDefault(e){
    e = e || event;
    if(e.preventDefault){
        e.preventDefault();
    }else{
        e.returnValue = false;
    }
}
addEvent(document,'dragover',preventDefault);
addEvent(document,'drop',preventDefault);
addEvent(targetArea,'dragenter',preventDefault);
addEvent(targetArea,'dragover',preventDefault);
addEvent(targetArea,'dragleave',preventDefault);
addEvent(targetArea,'drop',preventDefault);
targetArea.ondragenter = function(e){this.style.outline = "1px solid black";}
targetArea.ondragleave = function(e){this.style.outline = "";}
//拖拽选中
targetArea.ondrop = function(e){
    e = e || event;
    this.style.outline = "";
    var file = e.dataTransfer.files[0];
    base64(file);
}
</script>  

美高梅开户网址 17😉

 

 

出处:

于是乎想到对ActiveX再次回到的Base6四字符串进行编码操作

于是乎想到对ActiveX重返的Base6四字符串实行编码操作

base64 = System.Web.HttpUtility.HtmlEncode(base64);

MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));
base64 = System.Web.HttpUtility.HtmlEncode(base64);

MemoryStream stream = new MemoryStream(Convert.FromBase64String(base64));

运营程序,报“输入的不是可行的 Base-6四 字符串,因为它含有非 Base-6四字符、多个以上的填充字符,大概填充字符间包括违法字符”错误。

运维程序,报“输入的不是可行的 Base-6四 字符串,因为它涵盖非 Base-64字符、三个以上的填充字符,恐怕填充字符间包括违法字符”错误。

最后消除方案:

最终解决方案:

对Base6四字符串进行特殊字符替换,并打开PadRight操作,化解难题

对Base6肆字符串进行特殊字符替换,并开始展览PadRight操作,消除难题

string dummyData = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
if (dummyData.Length % 4 > 0)
{
    dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
}
MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));
string dummyData = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
if (dummyData.Length % 4 > 0)
{
    dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
}
MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));

终极提供一下包裹的Base6四Helper类,提供Base64字符串与公事之间相互转变操作。

最终提供一下卷入的Base6肆Helper类,提供Base64字符串与公事之间互相调换操作。

/// <summary>
    /// Base64编码字符串与文件转换帮助泪
    /// </summary>
    public class Base64Helper
    {
        /// <summary>
        /// Base64编码字符串转文件
        /// </summary>
        /// <param name="base64">Base64编码字符串</param>
        /// <param name="filename">文件完整路径</param>
        public static void ConvertBase64ToFile(string base64, string filename)
        {
            //base64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDwP45/tRfE/wDZx+FumaR4Ug1u2u7Oe5nk1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FR9lD6neIoPWvMf2Wb1NT8P64ws1t10nWF0OyghnlMUdpaW8SQqsbuyRnDsW2BQxOSKKKH8SHHY5D4jEj/goZ4AHr4Xn/APRWoV7+VB60UUR3ZQwjPBqM8HFFFUZhSOOM0UU1uBGVB5IoooqwP//";
            string dummyData = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
            if (dummyData.Length % 4 > 0)
            {
                dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
            }
            MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));
            //filename = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            Bitmap img = new Bitmap(stream);
            img.Save(filename);
        }

        /// <summary>
        /// 文件转Base64编码字符串
        /// </summary>
        /// <param name="fileName">文件完整路径</param>
        /// <returns></returns>
        public static string ConvertFileToBase64(string fileName)
        {
            //fileName = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            FileStream fs = File.OpenRead(fileName);
            BinaryReader br = new BinaryReader(fs);
            byte[] bt = br.ReadBytes(Convert.ToInt32(fs.Length));
            string base64String = Convert.ToBase64String(bt);
            return base64String;
        }
    }
/// <summary>
    /// Base64编码字符串与文件转换帮助泪
    /// </summary>
    public class Base64Helper
    {
        /// <summary>
        /// Base64编码字符串转文件
        /// </summary>
        /// <param name="base64">Base64编码字符串</param>
        /// <param name="filename">文件完整路径</param>
        public static void ConvertBase64ToFile(string base64, string filename)
        {
            //base64 = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAw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dy2UkjzKjKM7Yfk3MoLYGeTVG2h8P+H/ABYPCWjWttoXhDwZpZv9UxGbe0a5lZpEDtJb+U4jVZLh3ScOjvE8ifMrVctUuNJ0bXfjRrvhuGTVorK8fS4byE280Fgihkt2cvL5QlMKSvtC8su+MNHiuf8ADZk1/wCH3gb4U6f4is7ybVdFttV8RajoniOa+jltAqSSSQ3ZuobqSO4nYLHcbZA6b96gNioe4zpfhBb6jqtjffEvWWnW48T3C3NtbSXDMtrYqu22jCrdXEIYx/vGaEqrtIWKg5rsK5XUfiKmn/Gix+HFxdIqXejGaKEIAzzM0rKSxPICW02AvPUkYwR1pUHtVITIyoNN2HOKkKkUlVdgROn50xlB4NTkAio3Qn61SdwK7RjPNFS0UwJVAyBWL8UPE9/4I+GXiPxppMMMl1o+g3l9bR3CkxtJFC8ihgpBK5UZAIOO4ooqJASfD/RYtO0MavJe3V1eauEvL+5u5y7PI0aABRwsaKqgBECrwWwWZmbB+LD2+teNvB3w81iwiutL1m8vW1G2lZ9k6w2rkRSIG2SxtuO6ORWU4U4BUEFFR9lD6neIoPWvMf2Wb1NT8P64ws1t10nWF0OyghnlMUdpaW8SQqsbuyRnDsW2BQxOSKKKH8SHHY5D4jEj/goZ4AHr4Xn/APRWoV7+VB60UUR3ZQwjPBqM8HFFFUZhSOOM0UU1uBGVB5IoooqwP//";
            string dummyData = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
            if (dummyData.Length % 4 > 0)
            {
                dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
            }
            MemoryStream stream = new MemoryStream(Convert.FromBase64String(dummyData));
            //filename = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            Bitmap img = new Bitmap(stream);
            img.Save(filename);
        }

        /// <summary>
        /// 文件转Base64编码字符串
        /// </summary>
        /// <param name="fileName">文件完整路径</param>
        /// <returns></returns>
        public static string ConvertFileToBase64(string fileName)
        {
            //fileName = @"C:\Users\admin\Desktop\Tongji\test.jpg";
            FileStream fs = File.OpenRead(fileName);
            BinaryReader br = new BinaryReader(fs);
            byte[] bt = br.ReadBytes(Convert.ToInt32(fs.Length));
            string base64String = Convert.ToBase64String(bt);
            return base64String;
        }
    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图