无法将jpeg加载到片段中

时间:2018-06-05 23:41:02

标签: android

我正在尝试将图像从Android相机加载到片段中。             String imageFile = getArguments()。getString(" image");

        Log.d("Image",imageFile);

        File file = new File(imageFile);


        try {
            BitmapFactory.Options  options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            options.inJustDecodeBounds = true;

            Bitmap bitmap = BitmapFactory.decodeFile( file.getAbsolutePath() , options);

            Log.d("dimensions",options.outHeight + ":" + options.outWidth);

            options.inJustDecodeBounds = false;

            bitmap = BitmapFactory.decodeFile( file.getAbsolutePath() , options);


            if(bitmap == null){

                Log.e("Error", "could not create image");

            }else{
                imageBitmap = Bitmap.createScaledBitmap(bitmap,200,200,true);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

问题是BitmapFactory返回null作为位图,我无法弄清楚原因。

我的日志是:

 06-06 09:31:47.452 803-803/com.app D/Image: /storage/emulated/0/Android/data/com.app/files/Pictures/test1642442886.jpg
 06-06 09:31:47.453 803-803/com.app D/skia: --- SkAndroidCodec::NewFromStream returned null
 06-06 09:31:47.453 803-803/com.app D/dimensions: -1:-1
 06-06 09:31:47.453 803-803/com.app D/skia: --- SkAndroidCodec::NewFromStream returned null
 06-06 09:31:47.453 803-803/com.app E/Error: could not create image

0 个答案:

没有答案