Sri*_*idu 25 android bitmap imageview
我在main.xml中有一个Imageview,如何将位图设置为main.xml中的imageView我可以将位图分配给下面代码中的本地图像视图.
//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);
Run Code Online (Sandbox Code Playgroud)
sga*_*man 65
我在理解您的应用程序结构方面遇到了一些麻烦,但以下是我的建议:
改变你setContentView(img);的setContentView(R.id.main);
然后做:
ImageView mImg;
mImg = (ImageView) findViewById(R.id.(your xml img id));
mImg.setImageBitmap(img);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68338 次 |
| 最近记录: |