views:

194

answers:

1

I have a Imageview in main.xml, how to set the bitmap the to the imageView in main.xml i can assign bitmap to the local image view in the below code.

//Activates the Camera

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

// get the bitmap data from the Camera

     Bundle extras = data.getExtras();
     Bitmap b = (Bitmap) extras.get("data");
     int width = b.getWidth();
     int height = b.getHeight();
     ImageView img = new ImageView(this);
     img.setImageBitmap(b);

//Saves the image

     MediaStore.Images.Media.insertImage(getContentResolver(), b, timestamp, timestamp);

// Set the View

      setContentView(img);
+1  A: 

I'm having a little trouble understanding how you structured your app but here are my suggestions:

Change your setContentView(img); to setContentView(R.id.main);

Then do:

private ImageView mImg;
mImg = (ImageView) findViewById(R.id.(your xml img id));
mImg.setImageBitmat(img);
sgarman
Thank you, that works!
Srikanth Naidu