C#中图片.BYTE[]和base64string的转换
2017-04-26 23:08
369 查看
在C#中
图片到byte[]再到base64string的转换:
Bitmap bmp = new Bitmap(filepath);
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
string pic = Convert.ToBase64String(arr);
base64string到byte[]再到图片的转换:
byte[] imageBytes = Convert.FromBase64String(pic);
//读入MemoryStream对象
MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
memoryStream.Write(imageBytes, 0, imageBytes.Length);
//转成图片
Image image = Image.FromStream(memoryStream);
现在的数据库开发中:图片的存放方式一般有CLOB:存放base64string
BLOB:存放byte[]
一般推荐使用byte[]。因为图片可以直接转换为byte[]存放到数据库中
若使用base64string 还需要从byte[]转换成base64string 。更浪费性能。
图片到byte[]再到base64string的转换:
Bitmap bmp = new Bitmap(filepath);
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
byte[] arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(arr, 0, (int)ms.Length);
ms.Close();
string pic = Convert.ToBase64String(arr);
base64string到byte[]再到图片的转换:
byte[] imageBytes = Convert.FromBase64String(pic);
//读入MemoryStream对象
MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
memoryStream.Write(imageBytes, 0, imageBytes.Length);
//转成图片
Image image = Image.FromStream(memoryStream);
现在的数据库开发中:图片的存放方式一般有CLOB:存放base64string
BLOB:存放byte[]
一般推荐使用byte[]。因为图片可以直接转换为byte[]存放到数据库中
若使用base64string 还需要从byte[]转换成base64string 。更浪费性能。
相关文章推荐
- C#中图片.BYTE[]和base64string的转换
- C#中图片.BYTE[]和base64string的转换
- [转]C#中图片.BYTE[]和base64string的转换
- C#中图片.BYTE[]和base64string的转换方法
- C#中图片BYTE[]和base64string的相互转换
- 详谈C# 图片与byte[]之间以及byte[]与string之间的转换
- C# 图片与byte[]之间以及byte[]与string之间的转换
- C#中文件转换为byte[]及Base64String
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- c#中图片与Base64string 的转换
- C# 图片与byte[]之间以及byte[]与string之间的转换
- C# 图片与byte[]之间以及byte[]与string之间的转换
- c#中字节数组byte[]、图片image、流stream,字符串string、内存流MemoryStream、文件file,之间的转换
- C# string byte[] Base64 常用互相转换
- C# 图片与byte[]之间以及byte[]与string之间的转换
- C#中有关string和byte[]转换的问题
- C#中byte[]与string的转换
- [导入]C#中string与byte[]的转换帮助类
- C#中string与byte[]的转换帮助类
- C#中string与byte[]的转换帮助类