本篇文章给大家分享的是有关Java中怎么实现图片压缩。,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
第1种方法:谷歌开源工具
byte[] imageByte = frameInfo.getImageByte();
int size = imageByte.length;
frameInfo.setFileSize(size);
InputStream inputStream = new ByteArrayInputStream(imageByte);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
Thumbnails.of(inputStream)
.scale(1f)
.outputQuality(0.5f).toOutputStream(baos);
int testSize = baos.size();
InputStream in = new ByteArrayInputStream(baos.toByteArray());
StorePath storePath = storageClient.uploadFile(in, testSize, "jpg", null);
String imageUrl = storePath.getFullPath();
frameInfo.setFile_id(imageUrl);
frameInfo = pedestriansHandle(imageByte, frameInfo);
} catch (IOException e) {
e.printStackTrace();
}
以上就是Java中怎么实现图片压缩。,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注天达云行业资讯频道。