【发布时间】:2021-05-13 18:23:20
【问题描述】:
我现在面临一个问题。 Why Bitmap.decodeFile() method is returning null? 我尝试了以下建议。 但上述建议对我没有帮助。
代码:
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;
}
【问题讨论】:
标签: java android nullable android-bitmap bitmapfactory