【问题标题】:BitmapFactory.decodeFile() returning null for existing imageBitmapFactory.decodeFile() 为现有图像返回 null
【发布时间】:2021-05-13 18:23:20
【问题描述】:

我现在面临一个问题。 Why Bitmap.decodeFile() method is returning null? 我尝试了以下建议。 但上述建议对我没有帮助。

For directories reference

代码:

    private File createPhotoFile() throws IOException {
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
            String imageFileName = "IMG_" + timeStamp + "_";
            File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
            File image = File.createTempFile(imageFileName, ".png", storageDir);
            String mCurrentPhotoPath = image.toString();
    
            BitmapFactory.Options bmOptions = new BitmapFactory.Options();
            Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath,bmOptions);
            //bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
            Bitmap markedImage = waterMark(bitmap, "your_string", Color.RED, 90, 90, true);
    
            File file = new File("path");
            OutputStream os = new BufferedOutputStream(new FileOutputStream(String.valueOf(markedImage)));
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
            os.close();
            return file;
        }

【问题讨论】:

  • 可能类似的问题像这样one
  • 请回复@Darkman
  • 在创建后尝试添加bmOptions.inMutable = true 或尝试此answer
  • 把它作为这个帖子的答案,然后我会将你的回复标记为答案

标签: java android nullable android-bitmap bitmapfactory


【解决方案1】:

创建后尝试添加 bmOptions.inMutable = true 或试试这个 answer.

【讨论】:

    猜你喜欢
    • 2016-10-17
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多