[英]java.lang.ArithmeticException: divide by zero when compress image from pick gallery
我收到错误java.lang.ArithmeticException: divide by zero
当从选择库压缩图像时java.lang.ArithmeticException: divide by zero
。 这是我的代码:
public String compressImage(String filePath, String outputFilename) {
Bitmap scaledBitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
int actualHeight = options.outHeight;
int actualWidth = options.outWidth;
Log.i("INFO", "ActualHeight Input: " + actualHeight);
Log.i("INFO", "ActualWidth Input: " + actualWidth);
float maxHeight = 816.0f;
float maxWidth = 612.0f;
float imgRatio = actualWidth / actualHeight;
float maxRatio = maxWidth / maxHeight;
............
return outputFilename;
}
lin 中的错误: float imgRatio = actualWidth / actualHeight;
那么如何解决呢?
您收到异常的事实表明正在发生除以零,并且options.outHeight
返回零。 您需要找出发生这种情况的原因。 If Log.i("INFO", "ActualHeight Input: " + actualHeight);
返回null
以外的其他内容,请向我们提供更多详细信息。
请在您的清单中添加以下行(在 Application 块内)。
安卓:requestLegacyExternalStorage = "true"
希望,这将有助于解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.