In my app I prompt the user to capture an image. The users camera activity starts on a buttonClick and the user gets the option to use the camera to capture an image.
This image saves on the users phone. The image is then uploaded to firebase Storage and all is working good. Feedback from one user, using a Samsung Note 8, is that when the image is captured in portrait mode, he later in the app gets it displayed in landscape mode.
I looked in the firebase storage and found that the image is saved in the storage in LANDSCAPE mode, even though the user captured the image in portrait mode.
I guess I have to pass meta data to the jpeg file that the image is captured in portrait mode, for firebase to know that it actually IS portrait mode.
This is the code for capturing image:
private void takePhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
if (photoFile != null) {
imageUri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
This is the method CreateImageFile:
public File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyy.MM.dd_HH:mm:ss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"MAP_NAME");
if (!storageDir.exists()) {
if (!storageDir.mkdir()) {
return null;
}
}
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
And Finally the code for uploading the code for uploading the image to firebase Storage:
private StorageTask mUploadTask;
private void uploadFile() {
final String dateStamp = new SimpleDateFormat("dd MM").format(new Date());
final String timeStamp = new SimpleDateFormat("HH:mm:ss").format(new Date());
if (mImageUri != null) {
StorageReference fileReference = mStorageRef.child(System.currentTimeMillis() + "");
mUploadTask = fileReference.putFile(mImageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mProgressBar.setProgress(0);
}
}, 500);
When later displaying the image from the firebase storage, I use the picasso library like this:
Picasso.with(mContext)
.load(uploadCurrent.getImageUrl())
.placeholder(R.mipmap.ic_launcher)
.centerCrop()
.fit()
.into(holder.imageView);
Is it possible to detect the rotation with help from picasso ?
Exif Interface
and change orientation of image taken from camera/gallery before uploading to firebase storage, follow this answer – Heiskell