Android 在Iistview中获取相机图像
我有自定义的Android 在Iistview中获取相机图像,android,android-intent,camera,Android,Android Intent,Camera,我有自定义的列表视图。内部有一个按钮和图像视图 点击按钮,相机将打开。(相机意图已触发) 我希望捕获的图像(也称为位图)显示在ImageView上,它也是一个列表项 这意味着当我拍摄图像并按下相机的“完成”按钮时,我的imageview必须设置该图像 我如何才能做到这一点?按照以下步骤操作 根据您的活动中的相机意图结果启动活动 捕获图片后,控件回调到活动的onActivityResult 处理图像的路径 通过在listview项目位置设置属性来设置图像的路径 private static in
列表视图
。内部有一个按钮
和图像视图
点击按钮,相机将打开。(相机意图已触发)
我希望捕获的图像(也称为位图)显示在ImageView
上,它也是一个列表项
这意味着当我拍摄图像并按下相机的“完成”按钮时,我的imageview必须设置该图像
我如何才能做到这一点?按照以下步骤操作
onActivityResult
private static int FILE_SELECT_CODE_1 = 0;
function intentCamera(){
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, FILE_SELECT_CODE_1);
}
private String getLastImagePath() {
final String[] imageColumns = { MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA };
final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
Cursor imageCursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns,
null, null, imageOrderBy);
if (imageCursor.moveToFirst()) {
//int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
String fullPath = imageCursor.getString(imageCursor
.getColumnIndex(MediaStore.Images.Media.DATA));
// Log.d(TAG, "getLastImageId::id " + id);
// Log.d(TAG, "getLastImageId::path " + fullPath);
imageCursor.close();
return fullPath;
} else {
return "";
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FILE_SELECT_CODE_1 && resultCode == RESULT_OK){
String lastImagePath = getLastImagePath();
File fileImage = new File(lastImagePath);
Uri u = Uri.fromFile(fileImage);
//now you can set the image example:
ImageView img = new ImageView(this);
img.setImageURI(u);
}
}