访问从摄像头全分辨率的照片与MonoDroid [英] access to full resolution pictures from camera with MonoDroid
问题描述
我试图找到一种方法,从MonoDroid访问全分辨率的图片,之后试图端口的Java例子MonoDroid并期待在如何为别人似乎已经得到了,我现在有下面的很长一段时间(这不工作)
I'm trying to find a way to access full resolution pictures from MonoDroid, after a long time of attempting to port the Java examples to MonoDroid and looking at how for others seem to have gotten, i currently have the following (Which does not work)
private const int TAKE_PICTURE = 1;
protected Uri fileUri;
private void takePhoto(object sender, EventArgs e)
{
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
string path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"hqxmmc/pictures/ikbeneenplaatje.jpg");
Java.IO.File xfile = new Java.IO.File(path);
if (xfile.Exists())
{
Android.Util.Log.Warn("FILE", "file exists {0} \n overwriting!", xfile.Name);
xfile.Delete();
xfile.CreateNewFile();
}
else
{
Android.Util.Log.Warn("FILE", "file does not exist {0}, creating", xfile.Name);
xfile.Mkdirs();
xfile.CreateNewFile();
}
fileUri = Android.Net.Uri.FromFile(xfile);
Android.Util.Log.WriteLine(LogPriority.Warn, "FILE", fileUri.ToString());
intent.PutExtra(Android.Provider.MediaStore.ExtraOutput, fileUri);
StartActivityForResult(intent, TAKE_PICTURE);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null)
{
if (data.HasExtra("data"))
{
var thumbnail = data.GetParcelableArrayExtra("data");
Android.Util.Log.WriteLine(LogPriority.Info, "DATA", thumbnail.ToString());
// TODO Do something with the thumbnail
var outputFileUri = data.GetParcelableArrayExtra("outputFileuri");
Android.Util.Log.WriteLine(LogPriority.Info, "DATA", outputFileUri.ToString());
// TODO Do something with the full image stored
// in outputFileUri
}
}
else
{
//todo : reload full image form fileuri
Android.Util.Log.WriteLine(LogPriority.Info, "PATH", fileUri.ToString());
}
}
}
在'拍照'画面,我可以拍张照片,但该照片,然后保存到设备上的默认DCIM文件夹,忽略了文件名和我指定它的路径。
The 'take a picture' screen is displayed, i can take a picture, but that picture is then saved to the default DCIM folder on the device, ignoring the file name and path i specified for it.
在我保存的图片,OnActivityResult叫,但其意图数据
参数包含一个空的意图。
When i save the picture, OnActivityResult is called, but its Intent data
parameter contains an empty intent.
我如何获得访问全分辨率图像的图像我刚拍摄的和/或缩略图?
how do i get access to the full resolution picture and/or thumbnail of the picture i just shot?
推荐答案
我会简单地张贴,我已经用在我的项目code。希望它会帮助你。我也试图通过ContentValues类设置文件名和路径,像它在Android的维基描述,但一切都抿着嘴,我认为这是一些MonoDroid错误。
I'll simply posted the code that i have used in my project. Hope it will help you. I have also tried to set file name and path through ContentValues class, like it is described in Android wiki, but all was ineffectively, I think that it's some MonoDroid bug.
private string _imageUri;
private Boolean isMounted
{
get
{
return Android.OS.Environment.ExternalStorageState.Equals(Android.OS.Environment.MediaMounted);
}
}
public void BtnCameraClick(object sender, EventArgs eventArgs)
{
var uri = ContentResolver.Insert(isMounted ? MediaStore.Images.Media.ExternalContentUri
: MediaStore.Images.Media.InternalContentUri, new ContentValues());
_imageUri = uri.ToString();
var i = new Intent(MediaStore.ActionImageCapture);
i.PutExtra(MediaStore.ExtraOutput, uri);
StartActivityForResult(i, CAPTURE_PHOTO);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
if (resultCode == Result.Ok && requestCode == CAPTURE_PHOTO)
{
Toast.MakeText(this, string.Format("Image URI is {0}",_imageUri), ToastLength.Short).Show();
}
}
这篇关于访问从摄像头全分辨率的照片与MonoDroid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!