安卓 java。算术异常:从pick gallery压缩图像时被零除
从pick gallery压缩图像时出现错误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;
}
林中的错误:float imgRatio = actualWidth / actualHeight;
那么如何修复它呢
# 1 楼答案
得到异常的事实表明被零除正在发生,并且
options.outHeight
返回零。你需要弄清楚为什么会这样。 如果Log.i("INFO", "ActualHeight Input: " + actualHeight);
返回的不是null
的内容,请提供更多详细信息