C# 文件、byte相互转换
文件转byte数组:
         /// <summary>
         /// 将文件转换为byte数组
         /// </summary>
         /// <param name="path">文件地址</param>
         /// <returns>转换后的byte数组</returns>
         public static byte[] File2Bytes(string path)
         {
             if (!System.IO.File.Exists(path))
             {
                 ];
             }
             FileInfo fi = new FileInfo(path);
             byte[] buff = new byte[fi.Length];
             FileStream fs = fi.OpenRead();
             fs.Read(buff, , Convert.ToInt32(fs.Length));
             fs.Close();
             return buff;
         }
base64转文件:
         /// <summary>
         /// base64转文件
         /// </summary>
         /// <param name="base64Stream"></param>
         /// <returns></returns>
         public static string SaveLicensePhoto(string base64Stream, string savepath)
         {
             //string filepath = string.Empty;
             byte[] bytes = Convert.FromBase64String(base64Stream);
             MemoryStream ms = new MemoryStream();
             ms.Write(bytes, , bytes.Length);
             Bitmap bmp = new Bitmap(ms);
             string path = CommonHelper.MapPath(savepath);
             if (!Directory.Exists(path))
             {
                 Directory.CreateDirectory(path);
             }
             string filename = Guid.NewGuid().ToString() + ".jpg";
             bmp.Save(path + filename);
             return savepath + filename;
         }
C# 文件、byte相互转换的更多相关文章
- iconv 文件编码相互转换
		iconv 文件编码相互转换 示例: iconv -f utf-8 -t gbk ~/a.txt > ~/b.txt -f 从哪种格式转换 -t 要转换到哪种格式 a.txt要转换的文件 b.t ... 
- dword word byte 相互转换 .xml
		pre{ line-height:1; color:#800080; background-color:#d2c39b; font-size:16px;}.sysFunc{color:#627cf6; ... 
- C#中string和byte[]相互转换问题解决
		本来想讲string转换为byte数组,通过在VS上打 ‘str. “来找,结果半天没发现跳出来的函数中有想要的,哭瞎 /(ㄒoㄒ)/~~ 这回将两种情况都记下来了.... string ---> ... 
- WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换
		1 WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换 2012-12-18 17:27:04| 分类: Windows Phone 8|字号 订 ... 
- java 中 image 和 byte[] 相互转换
		java 中 image 和 byte[] 相互转换可恶的…………其实也挺好的 只是把好不容易写出来的东西记下来,怕忘了…… 下面,我来介绍一个简单的 byte[] to image, 我们只需要 ... 
- 文件-- 字节相互转换(word、图片、pdf...)
		方式一: /// <summary> /// word文件转换二进制数据(用于保存数据库) /// </summary> /// <param name="wo ... 
- C#图像处理:Stream 与 byte[] 相互转换,byte[]与string,Stream 与 File 相互转换等
		C# Stream 和 byte[] 之间的转换 一. 二进制转换成图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = 0; Ima ... 
- [uwp]ImageSource和byte[]相互转换
		最近做一个小app遇到一个问题,到目前还没有比较好的解决方法(可能是我查的资料不够多) 需求如下: 1.把一个Image中的图像保存到字节数组: 2.把字节数组转换为ImageSource,通过Ima ... 
- springboot ResponseEntity<byte[]> 下载文件 byte 都变成base64
		因为spring boot消息转换器 ,全部将数据转换为json格式,包括文件的byte数据 关于spring boot 的消息转换器见:https://www.jianshu.com/p/ffe56 ... 
随机推荐
- 小白学Python(13)——pyecharts 绘制 柱状图/条形图 Bar
			Bar-基本示例 from example.commons import Faker from pyecharts import options as opts from pyecharts.char ... 
- Python中map和reduce函数??
			①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ... 
- [ASP.NET Core 3框架揭秘] 依赖注入:依赖注入模式
			原文:[ASP.NET Core 3框架揭秘] 依赖注入:依赖注入模式 IoC主要体现了这样一种设计思想:通过将一组通用流程的控制权从应用转移到框架之中以实现对流程的复用,并按照“好莱坞法则”实现应用 ... 
- Webpack和Gulp对比
			Webpack和Gulp对比 作者 彬_仔 关注 2016.10.19 22:42* 字数 8012 阅读 2471评论 18喜欢 68 在现在的前端开发中,前后端分离.模块化开发.版本控制.文件合并 ... 
- spark复习笔记(3)
			在windows上实现wordcount单词统计 一.编写scala程序,引入spark类库,完成wordcount 1.sparkcontextAPI sparkcontext是spark功能的主要 ... 
- linux 配置 Sersync
			[root@SERSYNC sersync]# cp conf/confxml.xml conf/confxml.xml.bak.$(date +%F) [root@SERSYNC sersync]# ... 
- ubuntu16.04安装mysql数据库
			安装 sudo apt-get install mysql-server(安装过程中按提示设置root密码) sudo apt-get install mysql-client sudo apt-ge ... 
- C++使用静态类成员时出现的一个问题
			开发环境 Qt Creator 4.8.2 编译器 MinGw 32-bit 在类中定义了一个static data member class Triangular{ public: static b ... 
- python 日期封装
			import time import datetime import locale class TimeUtil: def __init__(self, curtime=None): self.cur ... 
- U盘安装win8(win7)+centos7双系统
			centos7除了之后,就像尝鲜看看,但是发现安装之后会失去win8启动项.导致重装系统,经过反复折腾,终于搞定了,发出来共享下.默认你的 window系统已经安装好,不介绍window安装过程.本文 ... 
