.jpg和.JPG for android有什么区别吗?

时间:2013-08-09 09:22:34

标签: android jpeg

我想知道图片展开.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手机上重复它。)

1 个答案:

答案 0 :(得分:1)

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

如果文件的扩展名为小写,例如:“.jpg”,那么您应该在源代码中引用。如果文件的扩展名为“.JPG”,则同样应该用代码编写。