【问题标题】:How to check if Image Quality is Low如何检查图像质量是否低
【发布时间】:2020-06-28 07:00:26
【问题描述】:

我正在开发一个 PhotoBook 应用程序,如果他们添加了低分辨率图像,我需要通知用户。我只需要像聊天簿应用一样显示“低分辨率图像,打印可能会受到影响”警告。

【问题讨论】:

  • 您可以检查图像大小。比如 long length = file.length() / 1024;
  • 你怎么解释
  • 您可以设置一个条件,例如如果图像大小为

标签: java android android-studio kotlin-extension


【解决方案1】:
int file_size = Integer.parseInt(String.valueOf(file.length() / 1024));     
if (file_size < 100){
   Log.v(TAG, "Low resolution image");
 }else{
  Log.v(TAG, "");
 }

【讨论】:

    【解决方案2】:

    您可以将图像转换为位图并检查其高度和宽度,从而帮助您检查图像分辨率。 如果图像来自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();
    

    如果图像高度和宽度小于您的需要而不是显示警报,请进行验证

    【讨论】:

      【解决方案3】:

      如果你有一个 Bitmap 对象,你可以检查 bitmap.getWidth() 和 getHeigth()

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-10-14
          • 2019-08-23
          • 2021-06-16
          • 2014-12-24
          • 2017-08-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多