How to take multiple images using camera in android - 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

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

Android Native Camera App Orientation Issue for selfie taken

Followed Android documentation to write code for launching native camera via intent:
http://developer.android.com/training/camera/photobasics.html
Problem: I am using Andorid Native Camera App for taking pictures from my app and launching via intent as mentioned in above link (MediaStore.ACTION_IMAGE_CAPTURE) and camera is launched successfully. When I click camera button of Native app to take pictures, image preview is mirrored while taking selfie (left image appears right) which selfie user would hate as image preview is not what he clicked.
Second - once image is clicked, it shows image preview and waits for user input for acceptance or rejection of picture.
Once image is accepted, OnStartActivityResult (as mentioned in above link) function receives the call and saves image to gallery. Strange thing here is that: Image gets inverted by 180 degree and then saved which is very weird behaviour.
Finally, two problems here: Image Preview Mirroing issue before user approves and while saving image invert issue (180 degree reverse).
Device: Samsung A6 Edge
Android: 5.1
Camera In Manifest File: Android.hardware.camera2 as Camera is deprecated
Please advise how can i fix above two issues.
Also- I have another doubt: Shall i use android native camera app or write the code using Camera Framework and launch custom camera? My requirement just to click pictures and show preview and save it with correct orientation. After searching a lot, I am doubtful - Can native camera app fix these issues? but your expert advise can help on this.
Any quick support and guidance on this is highly appreciated. Thanks in advance !
Here is the code:
public void triggerCamera() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imagePath = AppPhotoHelper.getOutputMediaFile();
// Continue only if the File was successfully created
if (imagePath != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(imagePath));
takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.setImagePath(imagePath);
this.startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
}
}
onActivityResult function:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK ) {
//AppPhotoHelper is my class to show image in gallery
AppPhotoHelper.displayInGallery(this.getImagePath(), this);
//Image captured and stored in gallery ... camera invoked for next shot after doing some business processing
this.triggerCamera();
}
else if (resultCode == RESULT_CANCELED) {
return;
}
else {
return;
}
}
}
As mentioned in my post, the native camera app differs from device to device. Did you try your code with another device or emulator? I published a library on github that solves many issues, including the image orientation across a wide variety of devices. Feel free to check it out, run the sample code on your device and check if it works properly for your use case.

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().

Using Intent for taking photo and edit preview

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.

Pdf editor. merging two activity

I am spending my days with practicing PDF editor.
I succed in loading Pdf files. and To edit the file I am using invisible activity over the file. Of course, activity is the 'editor'.
I can write and highlight things.
but the problem is the merging of these two activity.
I have to go to menu and click 'write' button to write.
and then PDF doesn't move any more because i am on 'editor'activity.
so I have to save the writings and exit the 'write'mode.
THis is super uncomfortable....I want it to be more simple.
'especially' those 'saving' part.. I really hate it.
'move' between two activities should be more natural without saving process...
Don't you have any good idea about this?
please help me out!!!!! new beginer is crying for anwser. Thanks for your time.
You would start your editor activity and wait for the result.
Something along the lines....
void goToEditMode() {
startActivityForResult(new Intent(this, PdfEditorActivity.class), SOME_REQUEST_CODE);
}
and then wait for the result...
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == SOME_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
extractData(data);
}
}
}
Assuming you passed your necessary data as an extra, implementing extractData(...) should be easy for the purpose.

Categories

Resources