如何检查图像质量是否低

How to check if Image Quality is Low

我正在开发一个 PhotoBook 应用程序,我需要在用户添加低分辨率图像时通知他们。我只需要像聊天簿应用程序一样显示 "Low-Resolution Image, Printing may be affected" 警告。

您可以将图像转换为位图并检查其高度和宽度,并以此帮助您检查图像分辨率。 如果图像来自 drawable,

 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.getWidth() 和 getHeigth()

int file_size = Integer.parseInt(String.valueOf(file.length() / 1024));     
if (file_size < 100){
   Log.v(TAG, "Low resolution image");
 }else{
  Log.v(TAG, "");
 }

您可以检查图像的宽度和高度,从而决定哪种分辨率适合将其归类为低质量。

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");
    }
}