Base64 编码图像压缩/调整大小
我有字符串格式的 Base64 编码图像。需要将其压缩/调整大小到不同的大小,即从这些压缩/调整大小的base64编码图像创建的图像文件具有不同的大小。
Java 中可以使用什么压缩/调整大小算法/jar?
I had base64 encode image in string format. Need to compress/resize it to different size, i.e. Image files created from these compressed/resized base64 encoded images are of different size.
What Compression/resize algorithm/jar can be used in Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
压缩的输出几乎总是二进制数据,而不是字符串......此时开始进行 Base64 转换是毫无意义的。
图像通常已经被压缩(大多数格式都使用压缩),因此您实际上不会获得太多好处。如果您确实需要字符串格式的数据,您可以尝试首先使用
GZipOutputStream
等压缩原始二进制数据,然后然后对其进行base64编码,但我怀疑你会节省很多空间。The output of compression is almost always binary data, rather than a string... at which point it's pointless doing the base64 conversion to start with.
Images are usually compressed already (most formats use compression) so you won't actually get much benefit. If you do actually need the data in a string format, you could try compressing the original binary data first using
GZipOutputStream
etc and then base64 encode it, but I doubt that you'll save much space.我使用这个函数返回 0.7 大小的图像。 (这是从 Selenium 返回的屏幕截图......如果我将其缩小得太小,图像就会开始看起来很糟糕。):
I'm using this function to return an image .7 the size. (This was for screenshots returned from Selenium.... the image started looking pretty bad if I scaled it down too far.):