1

I am using following code in onActivityResult but it is not working

File file1 = new File( Environment.getExternalStorageDirectory().getAbsolutePath(),imagecapture);

            if (file1.exists()) {
              //Do action
                image=(ImageView)findViewById(R.id.image);
             Bitmap myBitmap = BitmapFactory.decodeFile(file1.getAbsolutePath());
          image.setImageBitmap(myBitmap);
       image.invalidate();



            }

But I am not able to get why it is not working I have also used Android Camera Intent: how to get full sized photo? but it gives error on the line mImageUri = Uri.fromFile(photo); Any help will be Appreciated.

4

2 に答える 2

2
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 MainActivity extends Activity {
    /** Called when the activity is first created. */

    Button btnTakePhoto;
    ImageView imgTakenPhoto;
    private static final int CAM_REQUREST = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnTakePhoto = (Button) findViewById(R.id.button1);
        imgTakenPhoto = (ImageView) findViewById(R.id.imageView1);

        btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

          if (requestCode == CAMERA_PIC_REQUEST) {
              Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
              imgTakenPhoto.setImageBitmap(thumbnail);
          }
    }

    class btnTakePhotoClicker implements Button.OnClickListener
    {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
        }
    }
}
于 2012-06-05T07:40:26.047 に答える