我有以下代码:
public void take_picture(View view)
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
slikaa.setImageBitmap(photo);
}
现在我的问题是如何获取该图像路径(用于将其保存到我的数据库),然后再次使用它在图片中显示(我不知道如何获取字符串路径,然后重新使用它)
最佳答案
要在 onActivityResult 中获取图像路径,您需要通过发送带有 Intent 的图像路径来启动相机:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//ContentValues values = new ContentValues();
ContentValues values = new ContentValues(3);
values.put(MediaStore.Images.Media.DISPLAY_NAME, "testing");
values.put(MediaStore.Images.Media.DESCRIPTION, "this is description");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
imageFilePath = MainActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFilePath);
startActivityForResult(intent, CAMERA_REQUEST);
和onActivityResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ImageView slikaa = (ImageView)this.findViewById(R.id.slikaa);
if ((requestCode == CAMERA_REQUEST)&& (resultCode == Activity.RESULT_OK)) {
//get image from path
Bitmap photo = (Bitmap) data.getExtras().get("data");
photo = BitmapFactory.decodeStream(this.getContentResolver()
.openInputStream(imageFilePath), null, op);
slikaa.setImageBitmap(pic);
//slikaa.setImageBitmap(photo);
}
关于android - 使用android camera intent,获取uri,然后使用uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12122491/