我正在查看一些触发android.media.action.IMAGE_CAPTURE
意图并使用类级变量来存储结果图像的示例。我不想那样做。我想我应该能够给意图文件的 URI,然后在完成时从意图中取回该 URI。我正在尝试这样做:
void snapPixButton_Click(object sender, EventArgs e)
{
Intent cameraIntent = new Intent(MediaStore.ActionImageCapture);
File file = new File(Home.SnapStorageLocation, string.Format("{0}.jpg", Guid.NewGuid()));
cameraIntent.PutExtra(MediaStore.ExtraOutput, file.ToURI().ToString());
StartActivityForResult(cameraIntent, SnapPixIntentRequestCode);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (requestCode == SnapPixIntentRequestCode && resultCode == Result.Ok)
{
URI uri = new URI(data.GetStringExtra(MediaStore.ExtraOutput));
File file = new File(uri);
using (Bitmap bitmap = LoadAndResizeBitmap(file.Path, this.ImageView.Width, this.ImageView.Height))
{
this.ImageView.SetImageBitmap(bitmap);
}
}
}
但在 中OnActivityResult
,调用会data.GetStringExtra(MediaStore.ExtraOutput)
导致消息:未知标识符:MediaStore
我究竟做错了什么?我不认为我应该保留类级别的变量,我应该能够将数据传递给意图,然后再提取它,对吗?