Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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
Android-宽度和高度必须为>;图像文件压缩中的0_Android_Image Compression - Fatal编程技术网

Android-宽度和高度必须为>;图像文件压缩中的0

Android-宽度和高度必须为>;图像文件压缩中的0,android,image-compression,Android,Image Compression,我正在压缩一张图片,这张图片是用一种大多数时候都有效的方法从图库中获取的。代码如下: public static Uri compressImage(Context context, Uri inputUri){ String realPath = UtilityUriHelper.getPath(context, inputUri); File realFile = new File(realPath); File compressedImg = new Compre

我正在压缩一张图片,这张图片是用一种大多数时候都有效的方法从图库中获取的。代码如下:

public static Uri compressImage(Context context, Uri inputUri){
    String realPath = UtilityUriHelper.getPath(context, inputUri);
    File realFile = new File(realPath);

    File compressedImg = new Compressor.Builder(context)
            .setMaxHeight(1920)
            .setMaxWidth(1920)
            .setQuality(70)
            .setCompressFormat(Bitmap.CompressFormat.JPEG)
            .build()
            .compressToFile(realFile);

    return Uri.fromFile(compressedImg);
}
因此,当我一次又一次地拾取同一个图像时,有时会发生错误。错误为
宽度和高度必须大于0

我真的不明白为什么,有时候会发生,有时候不会


如果我必须检查宽度和高度,如何在发送到Compressor.Builder()之前获取宽度和高度?或者我应该在这里做些别的事情?

将其转换为位图。我需要将其作为文件上传到服务器。。还有其他解决方案吗?检查您是在拾取相同的图像,还是在同一个线程或不同的线程上工作?我认为它应该在同一个线程中,因为它不是异步的。我不擅长线程,所以可能会错误地将其转换为位图。我需要将其作为文件上载到服务器。。还有其他解决方案吗?检查您是在拾取相同的图像,还是在同一个线程或不同的线程上工作?我认为它应该在同一个线程中,因为它不是异步的。我不擅长穿线,所以我可能错了