base64和byte[]相互转换
来源:互联网 发布:网络终结者最好版本 编辑:程序博客网 时间:2024/06/07 03:32
/** * 上传图片获取图片base64码,然后解码,然后转成字节数组,以流的形式输出到本地 * @return * @throws Exception */ @RequestMapping(value = "/uploadYujhImg1", method = RequestMethod.POST) @ResponseBody public EntityServiceResponse<Map<String, String>> uploadYujhImg1(String fileImg) throws Exception { logger.info("uploadYujh"+fileImg); String imgBase64 = fileImg.replaceAll("data:image/png;base64,",""); BASE64Decoder d = new BASE64Decoder(); byte[] data = d.decodeBuffer(imgBase64); FileOutputStream os = new FileOutputStream("D:\\tupian\\d.jpg"); os.write(data); os.close(); return null; }/////////////////////////////////////////////////////////////////////////////////////////////读取本地图片输入流//将图片文件转化为字节数组字符串,并对其进行Base64编码处理public static void main (String arg[]) throws IOException {
//读取本地图片输入流
//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
String imgFile = "D:\\tupian\\a.jpg";//待处理的图片
InputStream in = null;
byte[] data = null;
//读取图片字节数组
try
{
in = new FileInputStream(imgFile);
data = new byte[in.available()];
in.read(data);
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder();
System.out.println(encoder.encode(data));//返回Base64编码过的字节数组字符串
}
阅读全文
0 0
- base64和byte[]相互转换
- Base64与byte[]相互转换
- byte和int相互转换
- BYTE 和 COleVariant 相互转换
- inputstream和byte[]相互转换
- BYTE 和 COleVariant 相互转换
- 【Android】Bitmap、InputStream、Drawable、byte[]、Base64之间的相互转换
- Byte[]和BASE64之间的转换
- Byte[]和BASE64之间的转换
- Base64处理byte[ ]和base64字符串之间的转换
- 文件和base64流的相互转换
- Base64和Bitmap的相互转换
- Bitmap和Base64的相互转换
- Android Base64和Bitmap相互转换类
- Bitmap和Base64的相互转换
- c# bitmap和base64编码相互转换
- java中 int和byte相互转换
- c# string和byte数组相互转换
- 原创视频|手把手教你用Axure做一个微信高保真原型(一)
- nginx配置默认首页
- 灰度变换和空间滤波
- vscode: Visual Studio Code 常用快捷键
- 线性代数中的一点理解和感悟
- base64和byte[]相互转换
- 专属程序猿的十一技能提升攻略!
- MySQL查询特定数据库中所有为空的表
- 第四周【项目3
- 第五周项目3
- 安装apk包
- Linux解压rar文件
- ElasticSearch 父子文档及多代父子文档(grandchild)解析之爸爸去哪儿了
- leetcode 141. Linked List Cycle和II