BitmapFactory不会在4.4.4中解码文件,但会在4.2.2中解码

时间:2015-03-12 17:33:07

标签: android bitmap bitmapfactory

我的onActivityResult()

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);期间会调用此代码

导致问题的具体行是                块末尾附近的Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);返回null,因此在尝试将位图传递给bitmap = cropSquare(bitmap);

时崩溃

它仅在4.4.4上崩溃,但在4.2.2上运行正常。 bmoptions已初始化,mCurrentPhotoPath也是。

                ImageView profilePhotoFld = (ImageView) findViewById(R.id.item_photo);
                /* There isn't enough memory to open up more than a couple camera photos */
                /* So pre-scale the target bitmap into which the file is decoded */

                /* Get the size of the ImageView */
                int targetW = profilePhotoFld.getWidth();
                int targetH = profilePhotoFld.getHeight();

                /* Get the size of the image */
                BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                bmOptions.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
                int photoW = bmOptions.outWidth;
                int photoH = bmOptions.outHeight;

                /* Figure out which way needs to be reduced less */
                int scaleFactor = Math.min(photoW/targetW, photoH/targetH);


                /* Set bitmap options to scale the image decode target */
                bmOptions.inJustDecodeBounds = true;
                bmOptions.inSampleSize = scaleFactor;
                bmOptions.inPurgeable = true;



                /* Decode the JPEG file into a Bitmap */
                Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);

                /* Associate the Bitmap to the ImageView */
                bitmap = cropSquare(bitmap);
                profilePhotoFld.setImageBitmap(bitmap);
                itemPhoto = bitmap;
                itemPhoto = itemPhoto.createScaledBitmap(itemPhoto,640,640,false);

1 个答案:

答案 0 :(得分:0)

在将我的应用程序与提供的示例应用程序进行广泛比较后确定。我的问题是我的清单文件中的 face palm

我有

<uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="18" />

显然是打算使用

<uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

感谢那些花时间思考我的问题的人。祝你们有美好的一天