java - 如何使用 Java 计算缓冲图像的 DPI
问题描述
首先,我必须将图像转换为 Base64,然后通过将 base64 转换为缓冲图像来计算图像的 DPI。
这是我尝试过的一些代码,它适用于 image.PNG(.png) 格式,但以其他格式返回 -1(错误输出),如 (.jpg)...!但我也需要这个也适用于其他格式。
private static float base64toBuffer(String inputbuffer) throws IOException, ImageReadException{
byte[] Rimage=decodeToImage(inputbuffer);
final org.apache.sanselan.ImageInfo imageInfo = Sanselan.getImageInfo(Rimage);
final int physicalWidthDpi = imageInfo.getPhysicalWidthDpi();
final int physicalHeightDpi = imageInfo.getPhysicalHeightDpi();
return physicalWidthDpi;
}
private static byte[] buffertoByte(String imageString) {
byte[] imageByte;
try {
BASE64Decoder decoder = new BASE64Decoder();
imageByte = decoder.decodeBuffer(imageString);
return imageByte;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
解决方案
推荐阅读
- c# - Windows 服务无法访问网络位置 (UNC) 路径
- node.js - Node.js - Firebase 导入返回在 Raspberry Pi 零上运行的非法指令
- python - Tensorflow 线性回归不收敛到正确值
- c++ - 反转字符串中单词的位置而不改变 O(1) 空间限制中特殊字符的顺序
- hive - Hive Bucket 上的最大功能
- asp.net-core - 在 Google Cloud Shell 中构建 .NET Core 2.1 应用程序失败
- excel - 如何在 vba 代码中调用用户定义的函数
- sql - SQL 来跟踪客户的旅程
- javascript - 为什么我要使用 RxJS 的 interval() 或 timer() 轮询而不是 window.setInterval()?
- batch-file - 如何将命令更改为您自己的命令