I was wondering if it were possible to take an image using the camera and then use that image in the background of my application. I am able to take and preview the image in my app, but don't know how to pass that data to the class that would set it as a background image. Is there a dynamic way to get this photo and set it as the background in my app?
Asked
Active
Viewed 1,087 times
0
-
Read this : http://stackoverflow.com/questions/5991319/capture-image-from-camera-and-display-in-activity – d.danailov Jul 08 '13 at 16:29
-
Thanks, But how do i then set that image as the background within my app, not just preview the image taken? – user2561473 Jul 08 '13 at 16:49
-
You need to start a new Camera Intent after that you need to get image. – d.danailov Jul 08 '13 at 16:56
1 Answers
1
To start the camera intent:
...
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(takePictureIntent, PHOTO_ACTIVITY_REQUEST_CODE);
...
Where PHOTO_ACTIVITY_REQUEST_CODE is just a integer constant unique within activity to be used as request codes while starting intent for results.
To Receive photo in the onActivityResult, and update background of the view
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PHOTO_ACTIVITY_REQUEST_CODE && data != null) {
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = (Bitmap) extras.get("data");
if (photo != null) {
// mView should refer to view whose reference is obtained in onCreate() using findViewById(), and whose background you want to update
mView.setBackground(new BitmapDrawable(getResources(), photo));
}
}
}
}
The above code does not use full size photo. For that, you will have to ask Photo intent to save it to a file, and read the file. Details are present here

Wand Maker
- 18,476
- 8
- 53
- 87