从字节MvvmCross的Andr​​oid绑定图像[] [英] MvvmCross Android Bind Image from byte[]

查看:125
本文介绍了从字节MvvmCross的Andr​​oid绑定图像[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何一个byte [](图片)绑定到一个AXML视图中的图像控制。 我的视图模型继承MvxViewModel。 我所有的其他绑定的伟大工程,但我不能找到一种方法来绑定的形象。

Does anyone know how to bind a byte[] (image) to a Image control in a axml view. My ViewModel inherit from MvxViewModel. All my other bindings works great but I cannot find a way to bind that image.

推荐答案

我想你可以使用一个自定义的UI控件绑定这一点。

I think you could bind this using a custom UI control.

要做到这一点,你需要做的是这样的:

To do this, you'll need to do something like:

  1. 在继承一个新的 MyImageView 的ImageView
  2. 添加默认的构造方法(通过上下文和属性到基构造)
  3. RawImage 属性添加到 MyImageView ,其实现为:

  1. inherit a new MyImageView from ImageView
  2. add the default constructor (which passes the context and attributes down to the base constructor)
  3. add a new RawImage property to MyImageView, implementing it as:

private byte[] _rawImage;
public byte[] RawImage
{
     get { return _rawImage; }
     set 
     {
             _rawImage = value;
             if (_rawImage == null)
                     return;

             var bitmap = BitmapFactory.DecodeByteArray(_rawImage, 0,_rawImage.Length);
             SetImageBitmap(bitmap);
     }
}

然后,您可以使用 MyImageView 在AXML而不是正常的 ImageView的控制

You can then use that MyImageView control in your axml instead of the normal ImageView.

请注意 - 这code以上没有测试 - 但一旦你得到的byte []中查看我敢肯定,你会工作了使用什么样的Droid的code

Note - this code above not tested - but once you get the byte[] in the View I'm sure you'll work out what Droid code to use.

作为一种替代方法,您也可以使用自定义绑定绑定字节[] 来正常的ImageView - 见<绑定定制的实例href="http://stackoverflow.com/questions/10700445/in-mvvmcross-how-do-i-do-custom-bind-properties/">In MvvmCross我该怎么做自定义的绑定属性

As an alternative approach to this, you could also use a custom binding to bind a byte[] to a normal ImageView - see an example of custom binding in In MvvmCross how do I do custom bind properties

这篇关于从字节MvvmCross的Andr​​oid绑定图像[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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