[英]How to check if Image Quality is Low
我正在开发一个 PhotoBook 应用程序,如果他们添加低分辨率图像,我需要通知用户。 我只需要像聊天簿应用程序一样显示“低分辨率图像,打印可能会受到影响”警告。
int file_size = Integer.parseInt(String.valueOf(file.length() / 1024));
if (file_size < 100){
Log.v(TAG, "Low resolution image");
}else{
Log.v(TAG, "");
}
您可以将图像转换为位图并检查其高度和宽度,从而帮助您检查图像分辨率。 如果图像来自可绘制,
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back);
bmp.getWidth(), bmp.getHeight();
如果来自uri的图像
Uri imageUri = data.getData();
Bitmap bitmap =
MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
bitmap.getWidth(), bmp.getHeight();
如果图像高度和宽度小于您的需要,则进行验证而不是显示您的警报
如果你有一个 Bitmap 对象,你可以检查 bitmap.getWidth() 和 getHeigth()
您可以检查图像的宽度和高度,从而确定适合将其归类为低质量的分辨率。
public void checkQuality() {
String filePathTmp = new File("").getAbsolutePath();//getCanonicalPath();
//notice you must use you image path
Path filePath = Paths.get(filePathTmp, "\\YOUR\\PARTH\\IMAGE.png").normalize();
ImageIcon imageIcon = new ImageIcon(filePath.toString());
int height = imageIcon.getIconHeight();
int width = imageIcon.getIconWidth();
System.out.println("HEIGHT: " + height + "--" + "WIDTH" + width);
//change values, consider your own criteria low quality
if (height <100 || width <100){
System.out.println("Low quality");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.