简体   繁体   English

如何检查图像质量是否低

[英]How to check if Image Quality is Low

I am developing a PhotoBook app where I need to notify the user if they add a low-resolution image.我正在开发一个 PhotoBook 应用程序,如果他们添加低分辨率图像,我需要通知用户。 I just need to show a "Low-Resolution Image, Printing may be affected" warning as chatbooks app do.我只需要像聊天簿应用程序一样显示“低分辨率图像,打印可能会受到影响”警告。

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

you can convert image into bitmap and check its height and width and with this its help you to check the image resolution.您可以将图像转换为位图并检查其高度和宽度,从而帮助您检查图像分辨率。 if image is from drawable,如果图像来自可绘制,

 Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back);
 bmp.getWidth(), bmp.getHeight();

if image from uri如果来自uri的图像

  Uri imageUri = data.getData();
    Bitmap bitmap = 
  MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
  bitmap.getWidth(), bmp.getHeight();

make a validation if image height and width less than your need than show your alert如果图像高度和宽度小于您的需要,则进行验证而不是显示您的警报

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

You can check the width and height of the image and thus you can decide which resolution is appropriate to classify it as low quality.您可以检查图像的宽度和高度,从而确定适合将其归类为低质量的分辨率。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM