How to set image Bitmap from internal storage? I checked my code and images are places internal storage, but problem with function SetImageBitmap Any help? Below there is my code, take picture save it to internal storage.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == Activity.RESULT_OK) {
String filename=currentImagePath.substring(currentImagePath.lastIndexOf("/")+1);
imageView.setImageBitmap(BitmapFactory.decodeFile(filename));
}
}
}
public void takepicture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = imageFile();
currentImagePath = photoFile.getAbsolutePath();
} catch (IOException ex) {
ex.fillInStackTrace();
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
@SuppressLint("SimpleDateFormat")
private File imageFile() throws IOException {
// Create an image file name
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(Constants.DEFAULT_DATETIME_FORMAT);
String imageFileName = DATE_FORMAT.format(new Date());
ContextWrapper cw = new ContextWrapper(getActivity());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
FileOperations.checkDirectory(directory, false);
return File.createTempFile(imageFileName, ".jpg", directory);
}
}