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


这段

代码是在我为我的Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); onActivityResult()期间调用的

导致问题的特定行是 块末尾附近的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);

在将我的应用程序与提供的示例应用程序进行广泛比较后,还可以。 我的问题是我的清单文件中的脸掌

我有

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

显然是打算使用

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

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

最新更新