使用 MonoDroid 从相机访问全分辨率图片 [英] access to full resolution pictures from camera with MonoDroid

查看:24
本文介绍了使用 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} 
 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 被调用,但它的 Intent data 参数包含一个空的意图.

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?

推荐答案

我将简单地发布我在我的项目中使用的代码.希望它会帮助你.我也尝试通过 ContentValues 类设置文件名和路径,就像在 Android wiki 中描述的那样,但一切都无效,我认为这是一些 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆