当前位置:网站首页>使用base64对图片进行编码、对byte[]进行编码
使用base64对图片进行编码、对byte[]进行编码
2022-07-13 17:47:00 【Kuo-Teng】
使用base64对图片进行编码
1. 对图片文件进行编码
import org.apache.commons.codec.binary.Base64;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class ImageBase64Utils {
/** * 将图片转换成Base64编码 * @param imgFile 待处理图片地址 * @return */
public static String getImgBase(String imgFile) {
// 将图片文件转化为二进制流
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();
}
// 图片头
//String imghead = "data:image/jpeg;base64,";
return Base64.encodeBase64String(data);
}
}
2. 也可直接传入byte[]进行编码,效率更高
byte[] data = XXXXXX;
String s = Base64.encodeBase64String(data);
边栏推荐
- 基础设施 NFTScan 正式发布 Solana 网络 NFT 浏览器
- 7. Cache breakdown, cache penetration, cache
- Test MySQL master-slave synchronization under win10
- Moss privacy computing all-in-one machine has passed 83 evaluations of Shenzhen Guojin evaluation center
- Hand to hand teaching - using native POI to import and export excel and the basic operations of Alibaba's easyexcel
- Clues in buuctf packets
- Mysql 主从服务器配置实验 centos7
- 图形图像编程实践 课程报告
- Flag under buuctf mask
- 网络通信安全部分笔记一
猜你喜欢

Buuctf backdoor killing

Network security emergency response - common tools

暑期沉淀web学习——php基础
![[an Xun cup 2019]easy_ web](/img/9d/f2c6fda2a96f4ac649dd553c9c2c55.png)
[an Xun cup 2019]easy_ web

Network security emergency response terminal detection and response technology

ES6 -- object

sniffer Pro對ARP協議的分析、捕獲與模擬攻擊

欧拉Talk | 开发者社区体验坦白局7月14日19:30约起

Compilation principle - parser design

网络通信安全部分笔记二
随机推荐
unity实验-控制游戏物体运动
PHP+JMeter模拟测试高并发场景。附代码。
MySQL-函数-字符串函数/数值函数/日期函数/流程控制函数
FTP upload file script description
Moss privacy computing all-in-one machine has passed 83 evaluations of Shenzhen Guojin evaluation center
unity实验-重力撞墙
Automatic deployment of server docking code cloud webhooks -- ultra detailed -- PHP
Log blacklist can really save you money!
Memory leak caused by ThreadLocal
内网渗透笔记——粘滞键与系统命令信息收集
Intranet penetration notes --:) a smiling face
内网渗透笔记——:)一个笑脸
利用Spark预测回头客实验报告
MySQL multi table query joint query / sub query
Test MySQL master-slave synchronization under win10
How did the situation that NFT trading market mainly uses eth standard for trading come into being?
The technology once selected in the top meeting completed the commercialization of ant chain and launched the copyright AI computing engine
ES6 -- array
服务器对接码云webhooks实现自动部署--超详细--PHP
摩斯隐私计算一体机全项通过深圳国金测评中心83项测评