How to display images in imageview picked or captured from camera I am trying this code but it only work if we pick it from gallery(from camera is not displaying) and image is in rotated form
private void pickImage() {
Intent pickIntent = new Intent();
pickIntent.setAction(Intent.ACTION_GET_CONTENT);
pickIntent.setType("image/*");
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String manufacturer = Build.MANUFACTURER;
if(!(manufacturer.contains("samsung")) && !(manufacturer.contains("sony")) && !(manufacturer.contains("lge"))) {
String filename = System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, filename);
Uri cameraPicUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri);
}
String pickTitle = "Select or take a new Picture";
Intent chooserIntent = Intent.createChooser(pickIntent, pickTitle);
chooserIntent.putExtra
(
Intent.EXTRA_INITIAL_INTENTS,
new Intent[]{takePhotoIntent}
);
startActivityForResult(chooserIntent, GALLEY_REQUEST_CODE);
}
And onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLEY_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
try {
InputStream inputStream = getContentResolver().openInputStream(data.getData());
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
int height = (int) getResources().getDimension(R.dimen.location_image_width);
int width = (int) getResources().getDimension(R.dimen.location_image_height);
Bitmap smallImage = Bitmap.createScaledBitmap(bitmap, width, height, false);
locationPhoto.setImageBitmap(smallImage);
} catch (Exception e) {
}
if (data == null) {
//Display an error
Constant.showLog("data null ");
return;
}
}
}