小编Ale*_*vit的帖子

ArithmeticException 偶尔被零除

我有一个 JAVA(在 Android 上运行)方法,偶尔会因除以零而捕获 ArithmeticException,尽管变量 inSampleSize 在循环之前设置为 1 并且每次只乘以 2。下面是原样的方法。知道我在这里缺少什么吗?谢谢!

public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
    // Raw height and width of image
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    try {
        if (height > reqHeight || width > reqWidth) {

            final int halfHeight = height / 2;
            final int halfWidth = width / 2;

            // Calculate the largest inSampleSize value that is a power of 2 and …
Run Code Online (Sandbox Code Playgroud)

java android

5
推荐指数
1
解决办法
363
查看次数

标签 统计

android ×1

java ×1