Android camera, how to set default format? - android

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.

Related

How to capture image without showing preview

Can anyone help to remove camera preview of open default camera.
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 100);
That is not possible. There are hundreds, if not thousands, of camera apps that support ACTION_IMAGE_CAPTURE. This includes dozens that are pre-installed ("default camera") on the thousands of different Android device models. Approximately zero of them offer this "feature", because ACTION_IMAGE_CAPTURE does not include that in its protocol.
No, it is not possible using the default camera using ACTION_IMAGE_CAPTURE as you are using. The API simply doesn't support that.
But if you really want to capture images without a preview, you have to do it yourself or use this library. This library does exactly what you are asking for. You can also check the code (it's pretty simple) and implement it yourself.

Can I get a squared image from a ACTION_IMAGE_CAPTURE intent

By default the image I can get after the camera app is done it will be rectangular. I wonder if it is possible to get the camera app to get square image without having to crop the original rectangular image.
No, sorry.
First, there is no documented option for ACTION_IMAGE_CAPTURE that offers this.
Second, there are thousands of device models, shipping with hundreds of camera apps pre-installed. Other camera apps can be installed by users. Any of those could handle your ACTION_IMAGE_CAPTURE request. None of those cameras have to offer square pictures at all, let alone by request from a third-party app.

Image overlay in android native camera

I am new into the android development environment. I want to know if there is a way to overlay an image into the android native camera, so I do not have to program an custom camera, just call the native camera, but into preview an image will be showed. I have tried many ways, but none of them seems to work.
Here is the code I use to shoot the picture and save the image:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File pictureDirectory = new File(Environment.getExternalStorageDirectory() + "/myPics");
String pictureName = getPictureName();
File imageFile = new File(pictureDirectory, pictureName);
Uri pictureUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Something like this face grid, but on top of the native camera:
!https://lh6.ggpht.com/8_x6orazogmW3sU9pnev2EzOalJkKi8ext1qzNTbbHdFCP5W0eKdVJk3KnMijf0nQw=h900
Thank You!
I want to know if there is a way to overlay an image into the android native camera, so I do not have to program an custom camera, just call the native camera, but into preview an image will be showed. Something like this face grid, but on top of the native camera
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, your code is not invoking an "android native camera" app. Your code is invoking the user's choice of what camera app to use, among the camera apps that the user has installed that support ACTION_IMAGE_CAPTURE. The user can easily choose to use some other camera app, if they prefer that camera app to the one that shipped with their device. So now you have hundreds, if not thousands, of additional camera apps to consider. Any of those could be what a given user is using.
Third, 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.
Fourth, you have no good way of determining when any of these camera apps happens to be in the foreground.

Capture image in Android via intent (ACTION_IMAGE_CAPTURE)

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.

Camera intent with resolution parameters in Android

I am building an Android application where part of the functionality involves users taking images and recording video.
For the application there is a need to set a specific resolution for both the images and the video.
Is it possible to specify the resolution parameters and then use a camera intent to capture images and video or do I need to build my own camera activity?
Any advice would be greatly appreciated.
Edit: I did some additional research and had a look at http://developer.android.com/guide/topics/media/camera.html#intents.
If I understand correctly there is no option to specify resolution parameters when using the Image capture intent http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE.
For the Video capture intent it seems I have the option to use the Extra Video Quality parameter, however that only gives me the option of high quality and low quality (which I am not quite sure what corresponds to in terms of resolution) http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_VIDEO_QUALITY
It seems I best get started developing my own image and video activities then, unless I missed some other options with the image and video intent.
Camera intent starts external camera applciation which MAY use your hints (but MIGHT NOT). The activity/application is non standard (phone vendor dependent), as well as the concrete implementation of the camera software.
You can also use the camera api ( working examples are in this project: http://sourceforge.net/projects/javaocr/ ) which allows you to:
query supported image formats and resolutions (you guessed it - vendor dependent)
set up preview and capure resolutions and formats (but camera software is free to ignore this setting, and some formats and resolutions can produce weird exceptions despite being advertised as supported)
Conclusion: cameras in android devices are different and the camera API is underdocumented mess. So be as defensive as possible.

Categories

Resources