【问题标题】:How do I set the Image source to something other than File in Xamarin?如何在 Xamarin 中将图像源设置为 File 以外的其他内容?
【发布时间】:2019-03-27 19:54:31
【问题描述】:

我试图让我的按钮图像显示,它作为字节数组存储在 sql 服务器中。我可以在 UWP 设备的根目录中设置一个存储在设备上的图像文件。

    <Button x:Name="MyButton" Text="Test Me">
        <Button.Image>
            <FileImageSource File="Forward.png" />
        </Button.Image>
    </Button>

MyButton.Image = "Forward.png";

...工作正常。我正在尝试做 Image.FromStream 或类似的事情。

【问题讨论】:

    标签: image button xamarin.forms


    【解决方案1】:

    从您的数据库中检索字节数组并将其传递到此代码中。

     public static Image ConvertBinaryToImage(byte[] data)
        {
            using (MemoryStream ms = new MemoryStream(data))
            {
                return Image.FromStream(ms);
            }
        }
    

    它将返回图像,然后您可以将其绑定到您的按钮。

    【讨论】:

    • 我从哪个库获取图像?
    • 使用 System.Drawing
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    相关资源
    最近更新 更多