How can i set an image taken from the Camera intent into a ImageView?

Newbie

in my app the user can take an image from the camera intent and then i want to return that image to an image view. How can i do that?

Here is my camera intent:

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);

And onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data)
    { 
        //Check that request code matches ours:
        if (requestCode == TAKE_PICTURE)
        {
            //Check if your application folder exists in the external storage, if not create it:
            File imageStorageFolder = new File(Environment.getExternalStorageDirectory()+File.separator+"Kruger National Park");
            if (!imageStorageFolder.exists())
            {
                imageStorageFolder.mkdirs();
                Log.d(TAG , "Folder created at: "+imageStorageFolder.toString());
            }

            //Check if data in not null and extract the Bitmap:
            if (data != null)
            {
                String filename = "image";
                String fileNameExtension = ".jpg";
                File sdCard = Environment.getExternalStorageDirectory();
                String imageStorageFolder1 = File.separator+"Kruger National Park"+File.separator;
                File destinationFile = new File(sdCard, imageStorageFolder1 + filename + fileNameExtension);
                Log.d(TAG, "the destination for image file is: " + destinationFile );
                if (data.getExtras() != null)
                {
                    Bitmap bitmap = (Bitmap)data.getExtras().get("data");
                    try
                    {
                        FileOutputStream out = new FileOutputStream(destinationFile);
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
                        out.flush();
                        out.close();
                    }
                    catch (Exception e)
                    {
                        Log.e(TAG, "ERROR:" + e.toString());
                    }

That all works but just want to add it now to my ImageView:

ImageView image = (ImageView) v.findViewById(R.id.imageV);
        image.setImageResource();

Could someone please help?

codermaster

Here's an example activity that will launch the camera app and then retrieve the image and display it.

package edu.gvsu.cis.masl.camerademo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MyCameraActivity extends Activity {
private static final int CAMERA_REQUEST = 1888; 
private ImageView imageView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.imageView = (ImageView)this.findViewById(R.id.imageView1);
    Button photoButton = (Button) this.findViewById(R.id.button1);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            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.setImageBitmap(photo);
    }  
} 

} Note that the camera app itself gives you the ability to review/retake the image, and once an image is accepted, the activity displays it.

Here is the layout that the above activity uses. It is simply a LinearLayout containing a Button with id button1 and an ImageView with id imageview1:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button1" android:layout_width="wrap_content"     android:layout_height="wrap_content" android:text="@string/photo"></Button>
<ImageView android:id="@+id/imageView1" android:layout_height="wrap_content"     android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>

</LinearLayout>

And one final detail, be sure to add:

<uses-feature android:name="android.hardware.camera"></uses-feature> 

and if camera is optional to your app functionality. make sure to set require to false in the permission. like this

<uses-feature android:name="android.hardware.camera" android:required="false"></uses-feature>

to your manifest.xml.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Set image taken from camera into an ImageView

From Dev

Trying to display image taken from camera intent

From Dev

ImageView does not display image taken from phone camera or photo gallery

From Dev

Set ImageView with selected Image from Camera or Gallery

From Dev

Save Image (took with Camera Intent) from ImageView to device (Gallery/SdCard)

From Dev

How to detect if photo was taken (camera intent)

From Dev

How to determine whether an image was taken from the library or from the camera

From Dev

How can I set an the image of an imageview for a specific file in Android?

From Dev

How can I download and set an Image on a ImageView on Android app?

From Dev

how can i set center (70%) croped image in imageview

From Dev

I want to read exif info in image in android. I can read exif from image in gallery but i cannot read exif photo taken from the camera

From Dev

taken from android camera image original resolution

From Dev

Saving image taken from camera into INTERNAL storage

From Dev

Read thumbnail image taken from phone camera

From Dev

How to pass an image from camera/camera roll to a new view after it has been chosen/taken?

From Dev

Resolution of image from camera to Imageview

From Dev

Resolution of image from camera to Imageview

From Dev

How can I show the image which is taken from restfull api using angularJs?

From Dev

How can I display a JPG image, taken from an API, in a Recyclerview in Android Studio?

From Dev

how can I set a dataset or datatable row to a value taken from a gridview textbox entry?

From Dev

Picture taken by intent and saved temp, how to display on imageview?

From Dev

put in a frame image taken from the camera or on own camera

From Dev

How to set image from drawable into imageview in Android

From Dev

I want to store image in sqlite database that is taken from gallery and camera android

From Dev

How can I save an image taken through AVCaptureSession

From Dev

How can I save only the last taken image to directory?

From Dev

How can I set the imageview with Picasso library?

From Dev

how can i set the camera function that anti-shake(image Stabilizer) at android

From Dev

How I can resize images taken from the Gallery?

Related Related

  1. 1

    Set image taken from camera into an ImageView

  2. 2

    Trying to display image taken from camera intent

  3. 3

    ImageView does not display image taken from phone camera or photo gallery

  4. 4

    Set ImageView with selected Image from Camera or Gallery

  5. 5

    Save Image (took with Camera Intent) from ImageView to device (Gallery/SdCard)

  6. 6

    How to detect if photo was taken (camera intent)

  7. 7

    How to determine whether an image was taken from the library or from the camera

  8. 8

    How can I set an the image of an imageview for a specific file in Android?

  9. 9

    How can I download and set an Image on a ImageView on Android app?

  10. 10

    how can i set center (70%) croped image in imageview

  11. 11

    I want to read exif info in image in android. I can read exif from image in gallery but i cannot read exif photo taken from the camera

  12. 12

    taken from android camera image original resolution

  13. 13

    Saving image taken from camera into INTERNAL storage

  14. 14

    Read thumbnail image taken from phone camera

  15. 15

    How to pass an image from camera/camera roll to a new view after it has been chosen/taken?

  16. 16

    Resolution of image from camera to Imageview

  17. 17

    Resolution of image from camera to Imageview

  18. 18

    How can I show the image which is taken from restfull api using angularJs?

  19. 19

    How can I display a JPG image, taken from an API, in a Recyclerview in Android Studio?

  20. 20

    how can I set a dataset or datatable row to a value taken from a gridview textbox entry?

  21. 21

    Picture taken by intent and saved temp, how to display on imageview?

  22. 22

    put in a frame image taken from the camera or on own camera

  23. 23

    How to set image from drawable into imageview in Android

  24. 24

    I want to store image in sqlite database that is taken from gallery and camera android

  25. 25

    How can I save an image taken through AVCaptureSession

  26. 26

    How can I save only the last taken image to directory?

  27. 27

    How can I set the imageview with Picasso library?

  28. 28

    how can i set the camera function that anti-shake(image Stabilizer) at android

  29. 29

    How I can resize images taken from the Gallery?

HotTag

Archive