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

谁都会走 提交于 2019-12-04 16:25:28

问题


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:


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);


来源:https://stackoverflow.com/questions/2928904/how-to-set-the-bitmap-to-the-imageview-in-main-xml-captured-from-the-camera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!