我是android的新手我不知道如何在图片中设置来自galary和相机的imageview。请帮助我..当我从相机中捕获图像未设置在imageview时看到下面的代码
private static final int CAMERA_REQUEST = 1888;
ImageView imageView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_capture);
imageView = (ImageView) this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.btncapture);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
答案 0 :(得分:0)
您将获得Uri
中onActivityResult()
文件的ContentResolver
,您需要找到Bitmap
中的路径f,然后创建 Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
profileImage.setImageBitmap(BitmapFactory.decodeFile(picturePath));
cursor.close();
。
例如 -
//*[table/tbody/tr/td/h3[text()='Opportunities']]/table[2]//td[@class=' dataCell ']