Bitmap not setting to ImageView [duplicate] - android

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

Related

How to draw on a photo IMMEDIATELY after taking it, THEN save to storage

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.

Saving Camera Bitmap to Storage, and Setting Image with Bitmap

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

cant take picture with android intent when rotating the screen in android

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.

Android camera (getting imageView from a different class)

I'm currently working on a app which the user can answer a question through images by taking photos or uploading photos from the album.
I've separated into two classes which are FulfillPhotoTaskActivity, AddPhotoActivity.
FulfillPhotoTaskActivity have imageView, addphoto button and save button.
when I press addphoto button, it goes to AddPhotoActivity which we can select two options(taking photos or uploading photos). I finished the part where if the user press take photo button then it opens the camera and take the photo. I created onActivityResult which get the image data. but in many example, inside the onActivityResult they also have imageView, like setImageBitmap.
My problem is, how can I get the imageView from the AddPhotoActivity and shows it in FulfillPhotoTaskActivity which I already made for XML.
When you take a photo it saves the image to a file. You can retrieve this image file and then you can call your imageView in FulfillPhotoTaskActivity and set the imageView to the image that is in the file.
The following code will start the camera intent and the file to a given location:
File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Folder/SubFolder");
String folder = root.toString();
File file = new File(folder, "fileName" + ".jpg");
Uri outputFileUri = Uri.fromFile(file);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, 0);
Now when the user takes a picture you know where it will be saved. In your FulfillPhotoTaskActivity you can call your imageview:
ImageView imageView = (ImageView)findViewById(R.id.YOUR_IMAGE_VIEW_ID);
Finally, you can just set the image to the imageview:
imageView.setImageBitmap(BitmapFactory.decodeFile(file));
So, you don't need to get the imageview from AddPhotoActivity. You only need the file name. Then, you can go back to FulfillPhotoTaskActivity and set the imageview to the bitmap file.
I hope this helps!

Android:Problem in passing image and its URI between two activities

Can we pass image and an image URI to other activity in same application using bundle?suggest me some way to do that?
USAGE :actually i have made an activity that crop an image taken from camera or from image stored in SD card depends upon the user.
and another app that uses a background image and a border image both are overlay so as to see PHOTOFRAME.
So now I want to combine both app so that the cropped image come from first app should become the background image for the second app.ie comes in photoframe.How can i do that?
Once you save your image in SD card
use this to cal the other activity.
final Intent intent = new Intent(MyClass.this, TargetClass.class);
final String root = Environment.getExternalStorageDirectory().getAbsolutePath();
intent.setData(Uri.parse(root + "/my/image/path/image.png"));
startActivity(intent);
if you are the reciever then you can get the path by calling
Uri path = getIntent().getData();
in the onCreate of the recieving activity. this is the standard way of checking for path by other activities.
Yes you can pass URI object,see putParcelable method in http://developer.android.com/reference/android/os/Bundle.html, URI already implements Parcelable interface,you can use corresponding get methods to get it.If any object that implements Parcelable interface then we can pass it using Bundle.

Categories

Resources