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.
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 am making an application using front camera and recently came up with this issue that outcomes of captured image and video are different(left-right inverted) from what I've seen through the display.
So for the image I could process it right after taking the picture because the size of the image wasn't too big - I used matrix preScale to mirror the image.
However, I have no idea how to do that with video capture. I already know that Android default camera does not mirror the front camera video output and lots of famous applications have compromised with default setting. But at the same time there are some camera related applications such as Instagram, Snow Camera, and B612 that do exactly what I want.
So my questions are,
Is it possible to mirror the front camera video output using Android MediaRecorder and Camera class? (That's what I've been using so far)
Or do you have to process the video after you take it? And if so, is there any nice and fast way of doing it?
It would be nice if any of you can answer it specifically. Thank you in advance!
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?
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).