Iam trying to capture a picture using
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_CODE);
}
}
but when i get the result, the orientation of the picture is not proper in most of the cases. Since I need to use the picture at a number of places, so I want the picture to be saved with the proper orientation. How can this be done?
Doubt :
1. Doesn't android default camera itself take care of the orientation when saving picture?
2. DO I have to use "ExifInterface" tweak every time when I display the picture from local?
the orientation of the picture is not proper in most of the cases
That depends on your opinion of what is "proper". Various device manufacturers and camera apps believe that having an EXIF orientation tag is perfectly proper.
How can this be done?
You are welcome to scan the image for the EXIF header and rotate the image yourself, but this is slow and memory-intensive.
Doesn't android default camera itself take care of the orientation when saving picture?
First, you are not necessarily using any "android default camera". Any camera app can respond to your Intent. There are thousands of device models, with hundreds of pre-installed camera apps, let alone apps that users might get from the Play Store or elsewhere.
Second, as noted above, some developers feel that "take care of the orientation" is having the appropriate EXIF header.
DO I have to use "ExifInterface" tweak every time when I display the picture from local?
Well, that depends. You could convert it once and save the converted image, then use the converted one going forward, rather than converting it every time. Whether or not it is appropriate for you to saving a converted image or not is up to you and your users.
Related
I want to capture image and upload to server from android client. The supported formats are jpeg,jpg and png. I am not making a custom camera in my application and am calling the camera using below code snippet:-
Intent intent = new Intent();
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(intent, REQUEST_CAMERA);
My doubts :-
Is there any guaranteed format(s) in which the native camera captures the picture?
Is there any way to command the camera to take image in a particular format?
(NB:- I know that I can achieve this by making a custom camera, but I dont want to do that)
Is there any guaranteed format(s) in which the native camera captures the picture?
No. Usually, it will be JPEG, as that is all that many camera apps know about. Possibly, the camera app might examine the MIME type associated with your Uri (e.g., via file extension) and do something based upon that.
But, please understand that there are ~2 billion Android devices, spread across thousands of device models. Those devices ship with hundreds of different pre-installed camera apps, and users can install others from the Play Store and elsewhere. The behavior of camera apps will vary widely, including having bugs.
Is there any way to command the camera to take image in a particular format?
No.
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.
I currently use this code to call the camera activity with a result which works fine.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getOutputMediaFile(stockT.getText().toString().toUpperCase())));
startActivityForResult(intent, 10);
I recently flashed latest cyanogenmod 10.2-20130915 and now I no longer have access to some of the stock camera features. I want to use org.cyanogenmod.focal to take the photos, since it supports so many features that I want and need.
Question
Is this possible to use a third party app like focal to return images as a result if so could you post some code to help me out?
Background (in case of another solution):
This app is used by me only. The app scans VINs and creates folder on the sdcard based on the stock number of the vehicle. I then use the camera intnet to take images and once returned the app shrinks them down to a specific size and jpg quality and saves them into their specific folder. Once I am finished with a set of vehicles I simply click a button and the adjusted images are uploaded to our server and pushed out to our vendors.
It turns out that the focal developers are going to actually include this activity. It is actually missing now so when the app is called it just opens like normal since it does not yet support this feature.
Is there a "secure" way to invoke the android camera with the intent MediaStore.ACTION_IMAGE_CAPTURE to capture a picture?
I am using the following code to take a snapshot from the camera:
Uri tempFile = Uri.fromFile(tempFile()); // returns a temporary stored files that is "Context.MODE_WORLD_WRITEABLE" so that android can put the file in this location
// tempFile looks like: file:///data/data/com.example.myapp/files/temp_picture.jpg
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra(MediaStore.EXTRA_OUTPUT, tempFile);
startActivityForResult(camera, Constants.REQUESTCODE_PICTURE_RESULT);
After that (returning from camera "RESULT_OK") I am copying the tempFile to the secured application store Context.MODE_PRIVATE and deleting the tempFile.
Everything works fine, the picture is taken and stored on the given Uri. But also the image is placed (in case of my current development device "HTC Sensation") in the galery
from my device (location is /mnt/sdcard/DCIM/100MEDIA/IMAG00XX.jpg). Why is the picture stored twice, I didn't even mention this location in my code? Is this a HTC "feature" or does the android camera store the file twice for media
scanning?
I also tried to get the Bitmap from the camera by omitting the MediaStore.EXTRA_OUTPUT parameter, but with this code I am only getting a thumbsize-picture from the camera (no full resolution).
I read a lot about the android camera, but I have to fetch an image from the camera in a "secured" way (no other app should read the data taken from the camera). I already
thought about implementing my own camera surface to catch a picture, but with this approach I must code a lot of stuff (flash, saturation, effects, zoom...) that the build in camera application already provides. Is it really that hard to take a picture on the android system?
If you want it to be 'secure', build camera functionality in your app. There is no way to be sure what some random camera app that comes pre-installed on a device does. They may be sending pictures to a server somewhere without you knowing. It's not super easy to do reliably, but you can only build the basic functionality. Failing that, require a specific app which you trust for image capture, by making the intent explicit (specify package name). This will, of course, require users to install it first if it is not already there.
I have implemented the camera in the same way as u have done. It creates the image and save it in the folder that i have created.but at the same time it saves image in the gallery as well. I have checked for this if other apps also does that or not. and found that even other apps does that and its not the issue of only HTC have tested it on various devices.even i am thinking how does it works.
My company has a need to print a timestamp on images taken on a droid. Another developer mentioned that we could wrap the entire functionality of the stock camera, then once a photo is taken, embed the timestamp on it. Can this be done, and if so, how simple/complex would it be?
Pretty simple actually. Definitely way simpler then writing a camera app from scratch.
Here is a short overview to give you a few keywords:
You need to fire a ACTION_IMAGE_CAPTURE intent,
this launches the devices camera app and prompts the user to take a picture (stock app or not doesn't even matter). When the picture is taken it will return to your app¹. At this point you'll get a file URI of the taken image that points to a JPEG usually.
Once you have that, load the image via the BitmapFactory into a Bitmap object and edit it by using a Canvas. You can use Canvas.drawText() to draw the text. Then store it where you need it, send it off the device or do whatever you want with it. And that's all the magic.
¹ here is a small example how to do that, found via google, there are plenty more out there