BitmapFactory.decodeFile() 为现有图像返回 null
BitmapFactory.decodeFile() returning null for existing image
我现在遇到一个问题。
我尝试了以下建议。
但是上面的建议对我没有帮助。
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;
}
创建后尝试添加 bmOptions.inMutable = true 或尝试此操作
.
我现在遇到一个问题。
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;
}
创建后尝试添加 bmOptions.inMutable = true 或尝试此操作