0

我想知道图像扩展名.jpg.JPG. 我遇到了无法使用以下代码打开 .JPG 图像的问题:

public static Bitmap decodeSampledBitmapFromResource(String path,
            int reqWidth, int reqHeight) {
        Log.e("PATH", path);
        // First decode with inJustDecodeBounds=true to check dimensions
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;

        // Calculate inSampleSizeа
        options.inSampleSize = calculateInSampleSize(options, reqWidth,
                reqHeight);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        Bitmap b = BitmapFactory.decodeFile(path, options);
        if(b!=null){
            Log.d("bitmap","decoded sucsessfully");
        }else{

            Log.d("bitmap","decoding failed; options: "+options.toString());
        }
        return b;
    }
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;
        Log.d("bitmap", "original options: height "+ height + " widnth "+width+" inSampleSize "+inSampleSize);

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

            // Calculate ratios of height and width to requested height and
            // width
            final int heightRatio = Math.round((float) height
                    / (float) reqHeight);
            final int widthRatio = Math.round((float) width / (float) reqWidth);

            // Choose the smallest ratio as inSampleSize value, this will
            // guarantee
            // a final image with both dimensions larger than or equal to the
            // requested height and width.
            inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
            Log.d("bitmap", "options: height "+ height + " widnth "+width+" inSampleSize "+inSampleSize);
        }

        return inSampleSize;
    }

如果我打电话

decodeSampledBitmapFromResource(path, 80, 60)

在 *.JPG 图像上,返回的位图为空。我在问它们是否通常以不同的方式实现,或者它是特定于 Galaxy S3 的?(我无法在 Galaxy Tab 7.7 或 HTC 手机上重复它。)

4

1 回答 1

1

Android 运行在 Linux 操作系统上,区分大小写。

如果文件的扩展名是小写的,比如:“.jpg”,那么你应该参考源代码。如果文件具有扩展名“.JPG”,也应该用代码编写。

于 2013-08-09T09:26:37.157 回答