i have a android application where i tae a picture in a intend like this:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(takePictureIntent, actionCode);
then i fill a ImageView with the result.
now i found a bug, then i want to take a picture and during the camera is open i rotate the screen and take the picture, i dont get a result in my ImageView.
Only when not rotating the camera, while taking a picture i see it in the ImageView.
how to solve this?
I assume you have a get results method.
Make sure your file location hasnt been cleaned because of rotate(aka you are looking in the wrong place).
I had this problem. I was setting a global variable of where to save the photo to.
I passed this to the intent to take photo, and on return looked at that location to display photo.
However, if you rotate the screen, the global variable is destroyed, and so on result, it no longer knows where to find the photo.
The best thing to do is to save it to the saved instance, and reinitialse location onResume from the savedInstance.
See here on how to do it.
Related
I have searched around and found a few different solutions to this problem but none of them are really what I am looking for.
I am developing an app that lets the user take an image by opening the camera via a MediaStore.ACTION_IMAGE_CAPTURE Intent as so...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
And then saves the image with
File photo = new File(Environment.getExternalStorageDirectory(), titleOfPhoto + ".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
I even get the thumbnail back and display it for the user in the onActivityResult() Override.
As the title suggests, what I would like to do is allow the user to draw on the captured image immediately after taking it. But I have no control over what happens between opening the camera and returning to my app with the captured image already saved. Apps like SnapChat and WhatsApp are doing exactly this and so much more, so I know it is possible, but Android does not appear to have this capability built in.
To be clear: The sequence of events needs to be
1) Open the camera
2) Take a picture
3) Draw on the picture
4) Press 'Ok'/'Done' or something
5) Save the edited photo
6) Return thumbnail
Is there anyway to add an event listener to the camera, or open the camera in a different manner that gives more control? Any help is appreciated! Thanks!
In order to do this, you will have to use the Camera Framwork API.
The basic of this is to render the camera output on a Surface View in your app. Then when the user takes a picture, capture the state of the surface view. From there you can allow your users to draw on the picture. When they are finished, THEN save the picture and display its thumbnail.
I've written a code for take a picture by using camera intent with ACTION_IMAGE_CAPTURE, and save picture into another directory with
camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
but if I change the intent with
INTENT_ACTION_STILL_IMAGE_CAMERA
picture is saved inside default picture android folder.
Is it possible to save picture into different folder with this kind of intent?
No,INTENT_ACTION_STILL_IMAGE_CAMERA intent action cannot be used because it does not return the captured image.It can only be done with ACTION_IMAGE_CAPTURE.
I know the basics on how to take a picture and set it to ImageView.
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
I want to do a little more than that.
I am saving it to a folder on to an SD card. That I have done successfully with this:
// intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUEST);
Here is my next question:
Not sure how to do this: What I'd like to do next: The next time I come to this Activity, I'd like to check if that image exists and assign it to that imageView.
Last days i faced this issue in one of my applications.
I'll try here to explain a little bitte what i have done.
Try to save the picture full path to a storage area or to your sharedpreferences.
Next time if you call your activity then check if a picture already exists and if you can use it.
Prepare in your xml layout an ImageView with visibility="gone" and if the point (2.) is true then you can change the visibility to visible and set the image in the view.
If the point (2.) is false then switch to camera view (SurfaceView) in order to take a new picture
You would have to use some sort of persistent storage to reference the file to check if it exists. I would just store it as a string in a preference and read it, then check if it exists and so on. Easy enough to do from the onCreate().
I know the basics on how to take a picture and set it to ImageView.
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
I want to do a little more than that.
I am saving it to a folder on to an SD card. That I have done successfully with this:
// intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(intent, CAMERA_REQUEST);
Here is my next question:
Not sure how to do this: What I'd like to do next: The next time I come to this Activity, I'd like to check if that image exists and assign it to that imageView.
Last days i faced this issue in one of my applications.
I'll try here to explain a little bitte what i have done.
Try to save the picture full path to a storage area or to your sharedpreferences.
Next time if you call your activity then check if a picture already exists and if you can use it.
Prepare in your xml layout an ImageView with visibility="gone" and if the point (2.) is true then you can change the visibility to visible and set the image in the view.
If the point (2.) is false then switch to camera view (SurfaceView) in order to take a new picture
You would have to use some sort of persistent storage to reference the file to check if it exists. I would just store it as a string in a preference and read it, then check if it exists and so on. Easy enough to do from the onCreate().
I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..