When I take a picture in portrait mode, the crop view automatically rotates it by 90 degrees. Does not seem to happen in landscape. Is there a way to prevent this
Change the file type from png to jpg
EDIT: Comments from Charles Caldwell, which explain why this answer is correct: "PNG files do not contain EXIF data which includes the rotation information. If the photo is taken as a PNG, switching to JPG could resolve the issue"
Related
I want to load an image from camera folder, but image has different orientation (rotated).
So I rotate it. When I create new file to save rotated image, the quality of that image is reduced.
I tried create new file from origin file without rotating it,
but quality image still reduced.
I think that image quality gets reduced when save image.
Issue: Rotating an image reduces image quality.
Any idea would be greatly appreciated.
Thanks
Picasso.with(mContext).load(lPreviewData.getImage()).into(holder.lPreviewIV);
This is how I am rendering the image url to ImageView. Unfortunately when i render an image it was showing in landscape mode but the actual image is in portrait.
This is a problem with exif rotation handling in Picasso. You should either rotate the image in code or fix the source image to have the correct orientation without using exif rotation.
I should also mention that this problem only affects images retrieved via url.
I've been trying to use the Android ACTION_IMAGE_CAPTURE intent and ACTION_GET_CONTENT intent to either take a photo or pick one. The problem I'm having is that when I when I try to take a photo using the Android photo intent in portrait mode, it saves it in landscape orientation.
I'm trying to save the Bitmap of the correctly orientated photo from a URI string.
I found this question: Android Camera Intent Saving Image Landscape When Taken Portrait, which is the exact same problem I'm having, but the answer is incomplete and didn't work for me. For example, what is the resizedBitmap, opts, and is file Uri.getPath()?
Well some cameras lock the landscape mode as default mode of camera(Samsung note 2) so if you take a picture in potrait mode the image is still saved in landscape mode. Most of the camera will add metadata into the image like the camera vendor, model,etc. Amongst various metadata that can be present the one we are intrested in is the rotation data. It specifies by what degrees the image is to be rotated. For knowing the rotation you can use ExifInterface class.
resizedBitmap Images are stored as bitmap objects in android. As an image can be large loading them whole into memory can lead to outofmemory error's and make your app consume more memory. So a bitmap is first resized to appropriate size and then loaded into memory.
opts By opts you must be referring to BitmapFactory.Options method. It is a class that provides methods to change the behaviour of bitmaps like making it mutable(is set to true you can apply effects like grayscale to this bitmap) , find its height and width in pixels without loading it to RAM,etc.
file Its a class used to perform CRUD operations in any file stored in the system.
Uri.getPath() this method returns the path where your image is stored or null.
If I take a photo with my camera in android in portrait mode, and then load it as a bitmap and draw it to a canvas it appears rotated counter clockwise 90 degrees and in landscape orientation. I use BitmapFactory.decodeFile(imagePath); to load the image. Does anyone know why this would happen?
Please see the answer at Android: Photos force captured in Landscape mode.
The bottom line is, capture preserves the hardware camera orientation, which is landscape in most telephones. You have few ways to find the actual orientation of the device vs. the horizon when the picture was taken, e.g. the EXIF header of the JPEG file. Bitmap method that decodes such file does not respect the EXIF info, even if it is present. But you can choose one of the ways to apply rotation to the bitmap after it is loaded.
An alternative is to apply rotation to the captured JPEG file, as described in Lossless JPEG Rotate (90/180/270 degrees) in Java?. There is even an app on the PlayStore to do it: https://play.google.com/store/apps/details?id=com.lunohod.jpegtool.
I am using the default camera of phone which is in Landscape mode. If i captured the image in Landscape mode it fits well in the imageview. But when i rotate the device the image rotates through 90 degree. The camera mode is still Landscape at that time. I am trying to find out when image is not captured in Landscape mode ie by rotating the phone not camera orientation.
Please see my answer to this question. Basically, you'll have to read the orientation information that is stored into the picture (EXIF meta data). There it is stored how the device was oriented, when the image was taken. In my answer, some code is given to rotate the image to be correctly shown in portrait mode.