Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用mvvmcross vnext在视图中显示相机拍摄的照片?_Android_Camera_Imageview_Xamarin.android_Mvvmcross - Fatal编程技术网

Android 如何使用mvvmcross vnext在视图中显示相机拍摄的照片?

Android 如何使用mvvmcross vnext在视图中显示相机拍摄的照片?,android,camera,imageview,xamarin.android,mvvmcross,Android,Camera,Imageview,Xamarin.android,Mvvmcross,我可以访问相机并拍照(使用PictureChooser插件),它将图片存储在android的图片库中,我只想在屏幕上显示并删除它(我不需要存储图片) 我该怎么做?(欢迎输入几行代码:))谢谢 ps:也许是mvvmcross的文件插件 编辑:谢谢你的回答,我认为对我来说最好的方法是做一个自定义绑定,将一个字节[]绑定到一个普通的ImageView,我看到了自定义绑定的示例(textview和button),并尝试制作我的 namespace Testa.Droid.Bindings { c

我可以访问相机并拍照(使用PictureChooser插件),它将图片存储在android的图片库中,我只想在屏幕上显示并删除它(我不需要存储图片) 我该怎么做?(欢迎输入几行代码:))谢谢

ps:也许是mvvmcross的文件插件

编辑:谢谢你的回答,我认为对我来说最好的方法是做一个自定义绑定,将一个字节[]绑定到一个普通的ImageView,我看到了自定义绑定的示例(textview和button),并尝试制作我的

namespace Testa.Droid.Bindings
{
    class PictureBinding : MvxBaseAndroidTargetBinding
    {
        private readonly ImageView _imageView;

        public PictureBinding(ImageView imageView)
        {
            _imageView = imageView;
        }

        public override MvxBindingMode DefaultMode
        {
            get { return MvxBindingMode.OneWay; }
        }

        public override Type TargetType
        {
            get { return typeof (byte[]); }
        }

        public override void SetValue(object value)
        {
            var memoryStream = new MemoryStream((byte[])valyue);
            Bitmap bitmap = BitmapFactory.DecodeStream(memoryStream);
            _imageView.SetImageBitmap(bitmap);
        }
    }
}
在Setup.cs中

protected override void FillTargetFactories(Cirrious.MvvmCross.Binding.Interfaces.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry)
    {
        base.FillTargetFactories(registry);

        registry.RegisterFactory(new MvxCustomBindingFactory<ImageView>("Picture", (imageView) => new PictureBinding(imageView)));
    }
现在在我看来,我不知道如何使用这个定制绑定

<ImageView
  android:id="@+id/image"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" 
  local:MvxBind="Picture ??, Mode=TwoWay" />



mvvcross vNext | monodroid

将图像上载到Web服务的内容包括

在ImageView中显示图像包含在


为了找到这些点击,我使用了StackOverflow搜索框中的单词“mvvmcross”和“picture”——


更新后更新(请尽量不要这样做-请尝试提出新问题-您可以随时交叉引用它们)

我只是稍微更改了更新中的绑定代码—它有字符串和流以及字节[]—所以我将所有内容都降低到字节[]级别,然后在ViewModel上添加了字节[]属性

要使用绑定,您现在应该能够使用:

 <ImageView
     android:layout_width="200dp"
     android:layout_height="200dp"
     local:MvxBind="Picture ImageBytes"
     />


请注意,您不需要双向-双向用于视图需要向ViewModel发送更改时-例如,当用户在文本框中输入文本时。

请注意@Livercool以前解决过此问题-请参阅-但未共享结果。希望您能解决这个问题,并在gist.github.com、twitter或博客上分享答案:)好的,非常感谢您的帮助。我刚刚解决了屏幕上图片的错误方向(图像应以90°向右的方向显示)。
 <ImageView
     android:layout_width="200dp"
     android:layout_height="200dp"
     local:MvxBind="Picture ImageBytes"
     />