图片 Base64码 转换
2024-09-11 09:08:18
import sun.misc.BASE64Decoder; private String getBase64Picture(String imgBase64Str) {
FileOutputStream fos = null;
String uuid = UUID.randomUUID().toString(); String staticPath = "d:/upsoft/test/img/";
String relativePath = "/test/img/"; File cutImgFile = new File(staticPath);
if (!cutImgFile.exists()) {
cutImgFile.mkdirs();
}
String picturePath = staticPath + uuid + ".jpg";
try {
byte[] fileDat = ImageStr2Bytes(imgBase64Str);
File file = new File(picturePath);
fos = new FileOutputStream(file);
fos.write(fileDat);
fos.close(); } catch (Exception e) {
e.printStackTrace();
}
return relativePath + uuid + ".jpg";
} public byte[] ImageStr2Bytes(String imgStr) {
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(imgStr);
return b;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
最新文章
- [LeetCode] Multiply Strings 字符串相乘
- jasoncpp读取jason数据如何判断某一字段是否存在
- List<;T>;保存为XML文件
- linux 打造man中文帮助手册
- React学习资料
- java.lang.IllegalArgumentException: addChild: Child name &#39;/SSHE&#39; is not unique
- JS增删改HTML表格
- bss段为什么需要初始化?
- JAVA 生成PDF报表()
- 【Java】Java垃圾回收机制
- Solr4.8.0源码分析(8)之Lucene的索引文件(1)
- mac下 配置 Apache Php Mysql
- angular ng-bind
- Vue-自带vue-resource插件实现http请求
- k8s
- CodeForces - 589B(暴力+排序)
- 洛谷p1732 活蹦乱跳的香穗子 二维DP
- k8s资料转载
- Spring RedisTemplate操作-xml配置(1)
- angularjs中的验证input输入框只能输入数字和小数点
热门文章
- 使用CSS如何悬停背景颜色变色 onmouseover、onmouseout
- XMPP得知--建立一个管理类
- 两个文件中的配置项设置方法和C比较程序处理
- sql pivot、unpivot和partition by用法
- axWindowsMediaPlayer1获取音频长度
- android:强大的图像下载和缓存库Picasso
- 【SSH进阶之路】一步步重构容器实现Spring框架——彻底封装,实现简单灵活的Spring框架(十一)
- 简单介绍如何使用PowerMock和Mockito来mock 1. 构造函数 2. 静态函数 3. 枚举实现的单例 4. 选择参数值做为函数的返回值(转)
- Android使用HttpURLConnection下载图片
- n每个计数的概率和发生骰子--动态规划