Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set the bitmap to the ImageView in main.xml captured from the camera?

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); 
like image 295
Srikanth Naidu Avatar asked May 28 '10 12:05

Srikanth Naidu


People also ask

How do you set the content of an ImageView in your XML layout file?

Navigate to the app > res > layout > activity_main. xml and add the below code to that file.

How do I get bitmap from ImageView?

Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)

Which attribute is used to set an image in ImageView?

src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.


1 Answers

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:

ImageView mImg; mImg = (ImageView) findViewById(R.id.(your xml img id)); mImg.setImageBitmap(img); 
like image 68
sgarman Avatar answered Sep 23 '22 06:09

sgarman