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);
Navigate to the app > res > layout > activity_main. xml and add the below code to that file.
Bitmap bm=((BitmapDrawable)imageView. getDrawable()). getBitmap(); Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)
src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With