Using Intent for taking photo and edit preview - android

I'm taking photo using following code:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
ImageView img = (ImageView) findViewById(R.id.imageView1);
img.setImageBitmap(photo);
}
}
I want to edit Preview before delivering to my app.
After taking photo a dialog shown that user must confirm photo. I want to edit image on this preview.
Update :
in fact I want to add a watermark to photo. When user click capture button, he must see an image with watermark and not original image!
Is it possible or I must use Camera API instead of Intent?

I want to edit Preview before delivering to my app.
There is no requirement that an ACTION_IMAGE_CAPTURE activity have any means to allow you to force the user to edit the image before it is returned to you in onActivityResult().
After taking photo a dialog shown that user must confirm photo.
There is no requirement that an ACTION_IMAGE_CAPTURE activity have any means to allow you to force the user to confirm the image before it is returned to you in onActivityResult().
The implementation of ACTION_IMAGE_CAPTURE activities is up to the developers of those activities, not you.
or I must use Camera API instead of Intent ?!
Using a native camera API will not help you, as the native camera API does not offer an image editor. If you want the user to edit an image, you will need to either try ACTION_EDIT on the image (which may or may not be supported on any given device) or add an image editor to your app.

Related

How to capture multiple image from Camera [duplicate]

I need a camera that allows me take multiple pictures at once and then select one. Others may or may not be stored on the device. I've tried this. I can take multiple images but how to select one and use it in my app? I read the documentation related to camera2 but its hard to understand without any practical example.I also tried these, but an isolated snippet won't help.
Any example related to the use of burst camera would help.
I do not expect a full code, but any directions on how to proceed? Is it possible to display the picture thumbnails as an when they are clicked on the camera screen itself. I'll need to have the bitmap of the image selected.
I can rephrase any part of the question if not clear.
Try this
you can Call your second startActivityForResult() from the onActivityResult() you get from your first startActivityForResult().
like this by this code you can get 10 pic
public int PIC_CODE=0;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
// get new image here like this
if(PIC_CODE<10){
// add new requset of picture like this
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
PIC_CODE++;
}
}
You have to implement your own camera to take multiple pictures. Create a class with surface view and implements SurfaceView.Callback. Please check out my library which will implement the same.
https://github.com/SripadRaj/BurstCamera

How to take multiple images using camera in android

I need a camera that allows me take multiple pictures at once and then select one. Others may or may not be stored on the device. I've tried this. I can take multiple images but how to select one and use it in my app? I read the documentation related to camera2 but its hard to understand without any practical example.I also tried these, but an isolated snippet won't help.
Any example related to the use of burst camera would help.
I do not expect a full code, but any directions on how to proceed? Is it possible to display the picture thumbnails as an when they are clicked on the camera screen itself. I'll need to have the bitmap of the image selected.
I can rephrase any part of the question if not clear.
Try this
you can Call your second startActivityForResult() from the onActivityResult() you get from your first startActivityForResult().
like this by this code you can get 10 pic
public int PIC_CODE=0;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
// get new image here like this
if(PIC_CODE<10){
// add new requset of picture like this
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
PIC_CODE++;
}
}
You have to implement your own camera to take multiple pictures. Create a class with surface view and implements SurfaceView.Callback. Please check out my library which will implement the same.
https://github.com/SripadRaj/BurstCamera

android open gallery via intent ACTION_PICK vs ACTION_GET_CONTENT

in my app i would like to have the user choose an image from the gallery and retrieve the result (thumbnail + full image uri). i would also like the user to be able to choose which gallery app to open (i.e. default gallery app or some other gallery app).
initially, according to this guide by google i copied and pasted this code:
public void selectImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_IMAGE_GET);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_GET && resultCode == RESULT_OK) {
Bitmap thumbnail = data.getParcelable("data");
Uri fullPhotoUri = data.getData();
// Do work with photo saved at fullPhotoUri
...
}
}
while it does get me the thumbnail and the full Uri in onActivityResult(...), the problem is that it does not open a chooser for the user to select which gallery app to use and instead it opens this thing (see images below), which i assume is a default "image-chooser" thing where you could select another app via a menu.
i feel it's silly that the user would have to open this default "image chooser" first and once they are already in an "image chooser", select the gallery app that they actually want to use (sure, the user could just choose the image from this thing, but i want to give them a convenient choice).
so i changed my code to this and it does indeed display a proper chooser for the user and he can go straight to hes favorite gallery app:
Intent intent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
if (intent.resolveActivity(getActivity().getPackageManager()) != null)
{
startActivityForResult(intent, Utils.REQUEST_CODE_OPEN_GALLERY);
}
however now i have a new problem: in onActivityResult(...) the line data.getParcelable("data"); returns null. in other words, i don't get back a thumbnail.
i also tried
Bundle extras = data.getExtras();
Bitmap thumbnail = (Bitmap) extras.get("data");
but "extras" is null.
is it possible to have a proper "app chooser" AND get back a thumbnail?
however now i have a new problem: in onActivityResult(...) the line data.getParcelable("data"); returns null. in other words, i don't get back a thumbnail.
You do not get that from ACTION_GET_CONTENT, either. You can tell this by reading the documentation for ACTION_GET_CONTENT. It is certainly possible that there are some buggy ACTION_GET_CONTENT activities that happen to return a thumbnail Bitmap in a "data" extra, but you should not assume that any user will have such a buggy ACTION_GET_CONTENT activity, let alone choose it. Besides, ACTION_GET_CONTENT is not limited to images; what would a "thumbnail" be of application/json or text/csv be?
Likewise, if you read the documentation for ACTION_PICK, you will see that there is no discussion of a thumbnail.
is it possible to have a proper "app chooser" AND get back a thumbnail?
No, insofar as you do not get a thumbnail back from anything except ACTION_IMAGE_CAPTURE, and that is for taking photos.

Get path of image from intent when using camera and putting EXTRA_OUPUT parameter

I'm currently creating a functionnality for the user to upload images to my server. He can either takes pictures with his camera or from his gallery.
I'm using this code to take a picture with the camera :
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
tempFile = File.createTempFile(String.valueOf(System.currentTimeMillis()), ".jpeg", ContextCompat.getExternalCacheDirs(a)[0]);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
And then to manipulate the image I use onActivityResult as such :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// use tempFile to recreate bitmap and do some heavy-wooshy-wishy stuff
...
}
}
It works totally fine but I'm confused with the Intent data parameter when using the camera. In this case it is null and to use the taken picture I need to re-create it from the path I gave to the ... intent.
What I find especially confusing is that if I don't put any EXTRA_OUTPUT parameter, then the Intent data isn't null and I can easily get the path of the picture with data.getData().
BUT THEN I just get a thumbnail from the original picture.
Is there any way to get the original picture from the camera and the path from the intent ? I don't have any real use case, but let's say the tempFile field gets modified or destroyed when you're taking the picture. Then on onActivityResult you will not be able to use the just taken picture.
What I find especially confusing is that if I don't put any EXTRA_OUTPUT parameter, then the Intent data isn't null and I can easily get the path of the picture with data.getData().
Not generally. There is no requirement for ACTION_IMAGE_CAPTURE to provide you a path to anything. Getting a thumbnail back via the data extra, if you do not provide EXTRA_OUTPUT, is the only "result" that you are supposed to get back in onActivityResult().
Is there any way to get the original picture from the camera and the path from the intent ?
No, because you never get the path from the Intent. It may be that a few camera apps leak this information. Not all will.
but let's say the tempFile field gets modified or destroyed when you're taking the picture
It is your job to not make that sort of mistake. For example, make sure that you retain this value across configuration changes and short-lived process termination, via onSavedInstanceState().

How to get the path to the last image captured by Android camera?

I am using the built-in camera in my Android app and having problems getting the path to the last captured image.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
....
}
Intent data contains a thumbnail of the last captured image, not the actual image saved to the SD card. So, how do I get the path to the actual full size image?
Thanks in advance.
This SO answer is probably what you are looking for:
How to pick an image from gallery (SD Card) for my app?
Alternatively, you could set the path for the picture manually before starting the Camera activity. You could add this path like this:
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(FILE_PATH));
Then on the result, you check if the resultCode is RESULT_OK, and use the path of the image you already know.

Categories

Resources