Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检查图像质量是否低_Java_Android_Android Studio_Kotlin Extension - Fatal编程技术网

Java 如何检查图像质量是否低

Java 如何检查图像质量是否低,java,android,android-studio,kotlin-extension,Java,Android,Android Studio,Kotlin Extension,我正在开发一个PhotoBook应用程序,如果用户添加低分辨率图像,我需要通知用户。我只需要显示一个“低分辨率图像,打印可能会受到影响”警告,就像chatbooks应用程序一样。您可以将图像转换为位图并检查其高度和宽度,这有助于您检查图像分辨率。 如果图像来自drawable Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.back); bmp.getWidth(), bmp.getHeight(); 如果图像来自uri

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

您可以将图像转换为位图并检查其高度和宽度,这有助于您检查图像分辨率。 如果图像来自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)); 如果(文件大小<100){ Log.v(标签,“低分辨率图像”); }否则{ Log.v(标记“”); }
您可以检查图像的宽度和高度,从而确定哪种分辨率适合将其归类为低质量

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");
    }
}
public void checkQuality(){
字符串filePathTmp=新文件(“”)。getAbsolutePath();//getCanonicalPath();
//请注意,必须使用图像路径
Path filePath=Path.get(filePathTmp,“\\YOUR\\PARTH\\IMAGE.png”).normalize();
ImageIcon ImageIcon=新的ImageIcon(filePath.toString());
int height=imageIcon.getIconHeight();
int width=imageIcon.getIconWidth();
System.out.println(“高度:“+HEIGHT+”--“+”WIDTH“+WIDTH”);
/改变价值,考虑你自己的标准,低质量

if(height)您可以通过图像大小进行检查。如long length=file.length()/1024;如何解释您可以设置一个条件,如图像大小<100 kb,然后显示一条警告消息。
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");
    }
}