当前位置:网站首页>将本地上的图片转换成Base64编码
将本地上的图片转换成Base64编码
2022-04-23 21:59:00 【多汁多味】
导入需要的包:
import java.io.*;
import java.util.Base64;
使用Java根据本地上保存图片的地址转为Base64编码
/**
* 将图片转换成Base64编码
* @param imgFile 待处理图片
* @return
*/
public static String ImgToBase64(String imgFile){
//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
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();
}
return new String(Base64.getEncoder().encode(data));
}
版权声明
本文为[多汁多味]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43652507/article/details/124370438
边栏推荐
- [leetcode sword finger offer 58 - I. flip word order (simple)]
- This paper solves the cross domain problem of browser
- Hystrix components
- JS to get the browser and screen height
- Detailed explanation of basic assembly instructions of x86 architecture
- Display, move, rotate
- 2022-04-24日报:在生物科学领域应用深度学习的当前进展和开放挑战
- 在线时序流程图制作工具
- ERP function_ Financial management_ The difference between red and blue words in invoices
- JS prototype and prototype chain
猜你喜欢
OpenFeign调用详细日志展示
[leetcode refers to offer 47. Maximum value of gift (medium)]
OpenFeign组件的简介和使用
MySQL back to table
一文解决浏览器跨域问题
Handling of alternative solutions for openfeign integration with hystrix
Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
IIS cannot load * woff,*. woff2,*. Solution of SVG file
Question brushing plan - depth first search (II)
MVC three-tier architecture (illustration)
随机推荐
Database Experiment 2 data query
IIS cannot load * woff,*. woff2,*. Solution of SVG file
MySQL 回表
Oracle ora-01033: Oracle initialization or shutdown in progressprocess solution
在线Excel转CSV工具
The computer is out of power. How did I pass the terrible interview of Tencent cloud?
Daily operation and maintenance knowledge -- 1
Detectron2 usage model
[leetcode refers to offer 27. Image of binary tree (simple)]
Hystrix components
Online Excel to CSV tool
OpenFeign之响应处理
服务雪崩效应
LabVIEW修改应用程序窗口外观
[leetcode sword finger offer 28. Symmetric binary tree (simple)]
ROS learning notes - tutorial on the use of ROS
Problem brushing plan -- dynamic programming (IV)
Sklearn function: Train_ Test_ Split (split training set and test set)
分布式系统服务熔断
【SDU Chart Team - Core】SVG属性类设计之枚举