我在看一些觸發android.media.action.IMAGE_CAPTURE
意圖的示例,並使用類級變量來存儲結果圖像。我不想這樣做。我認爲我應該能夠給出意圖文件的URI,然後在完成時從意圖中獲取該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
我在做什麼錯?我認爲我不應該保留類級變量,我應該能夠將數據傳遞給意圖,然後再提取它,對吧?
檢查:http://stackoverflow.com/questions/6341329/built-in-camera-using-the-extra-mediastore-extra-output-stores-pictures-twice –
@PareshMayani:謝謝,那篇文章doesn'儘管我很好的回答了我的問題。 –