I have very typical custom camera implementation. I'm using Camera.takePicture(...) method to take photos. And usually photos that are taken using front camera are horizontally inverted (mirrored). I'm totally fine with it, but I've noticed that on some devices it's not true and photos are not inverted. I would like to have a consistent behavior for all devices. So is there a way to know whether a photo is not inverted?
Related
Is there a way I can get an image from a camera preview? The purpose of this would be to overlay an emoji over the face of the camera preview, and I can't overlay the emoji images without first having a Bitmap image as follows:
private void processAndSetImage()
{
mResultsBitmap = OverlayEmoji.detectFacesandOverlayEmoji(this, mResultsBitmap);
mImageView.setImageBitmap(mResultsBitmap);
}
Is there a way that mImageView could have the value of a camera preview? Any links to other SO posts, or articles (in java) would be greatly appreciated!
Is there a way I can get an image from a camera preview?
No.
First, there are thousands of Android device models. These devices will have dozens, if not hundreds, of "android native camera" apps, as many device manufacturers frequently ship a customized camera app.
Second, there is no requirement that all camera apps have an identical user interface. The size and position of the camera preview can vary. Not only will they vary between apps, but even the same app might vary the size and position of the camera preview between versions of that app, as apps can and do get updated.
Third , you have no good way of determining when any of these camera apps happens to be in the foreground.
I'm using
Intent(MediaStore.ACTION_IMAGE_CAPTURE)
to get a photo from the camera, it works fine on all devices, except for samsung devices where if you take photo with the frontal camera it appears rotated 180 degrees.
I can rotate the image 180 degrees to correct the issue with the frontal camera, but this causes the rear camera photos to be rotated as well.
Is there any way I can detect which camera is taking the picture, and therefore only rotate the frontal camera's images?
it works fine on all devices
No offense, but I rather doubt that. There are a lot of buggy camera apps. Bear in mind that some of those buggy camera apps are user-installed, not just pre-installed.
Is there any way I can detect which camera is taking the picture
Not really. I do not see an EXIF tag for that, and there is no requirement that the camera app put the tag in the image anyway. You are not told any details about the picture other than the picture itself. You could try playing some games, looking at the image resolution and comparing it with possible camera resolutions, but that will be unreliable.
In general, with ACTION_IMAGE_CAPTURE, you just wind up living with spotty results. Your primary alternative is to use a library to embed photo capture into your app (e.g., CameraKit-Android, Fotoapparat), trading off the unreliability of third-party camera apps with the unreliability of device manufacturer camera API support.
In my application, i want to take picture using built-in camera application. Taking picture process is working fine. I want to know is picture taken from front camera or back camera, because after taking picture i want to get the rotation angle and rotate the picture to that angle and store it in sdcard. ExifInterface always return the same angle(90) rather user take the picture from front/back camera. When user take the picture from back camera, rotation is fine but when user take the picture from front camera, picture rotation is wrong. Please suggest any solution for this problem.
Thanks
I believe that your device does something wrong with the rotation flag. You should try other devices, too.
Note that MediaStore.ACTION_IMAGE_CAPTURE may be fulfilled by different Camera apps on different devices, or even on the same device: the end user is free to choose. Some downloaded applications will respect an extra to choose the front camera (see https://stackoverflow.com/a/11159760/192373), other won't. Some will do a better job to provide correct EXIF, others will mess it up.
This question may be slightly philosophical in nature, but would it be crazy to just capture a photo from the live preview instead of going through takePhoto?
I've found a few examples of how to do so: How to capture preview image frames from Camera Application in Android Programming? and Capture an image from the camera preview.
Right now I'm juggling through inconsistent different EXIF rotation behavior on various phones (it looks like you have a FullExifFixup for all Samsung devices, but I'm having different behavior between my S2 and S4) and I'm wondering if it wouldn't just be easier to grab the preview image.
Is this a stupid idea?
but would it be crazy to just capture a photo from the live preview instead of going through takePhoto?
It would be crazy with the library as it stands, simply because I don't expose the preview frames. :-) That's on the issue list.
it looks like you have a FullExifFixup for all Samsung devices, but I'm having different behavior between my S2 and S4
I don't have an S2 at the moment. If you can provide me with a reproducible test case (including details of the specific model of S2), post an issue, and I can see what I can do.
I'm wondering if it wouldn't just be easier to grab the preview image
It won't be at full resolution of the camera -- you'll be capped at the preview frame size. That being said, plenty of apps work with just the preview frames. Vine, for example, captures its video by capturing the preview frames, due to various problems they ran into when using MediaRecorder (there's a conference talk from a Vine employee that goes into more details).
I am trying to build a receipt scanning Android app and the way that I am handling really long receipts is to take multiple pictures and compile them into one long image. I tried doing image stitching with opencv but I ran into too many memory issues on older devices.
I am now running into the issue that with certain devices, specifically the Samsung Galaxy Player and Samsung Galaxy Tab 2, the preview and image capture orientation are not correct. The receipt needs to be scanned in portrait mode.
I have tried using this code to rotate the preview: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29
I added a line of code that rotates the camera by the same value that it rotates the preview.
On the Galaxy Player, this makes the preview display as still rotated but now flipped. The pictures that it returns are still rotated as if the camera was not rotated.
On the Galaxy Tab the preview displays correctly but the image that it creates is upside down.
Is there a way to detect the top and bottom of the image without saving it to file and getting the EXIF? Would that even make a difference on these devices or is there a deeper issue with those devices?
Thanks!