WriteableBitmap不能在Linux上渲染,但可以在UWP和Wasm上工作

问题描述

我正在尝试使用WriteableBitmap对象在UI上呈现一个红色框。该应用程序可以在UWP上正常工作:

UWP

在使用Gtk.Skia的Linux上,什么都没有显示(共享相同的代码):

Linux.Gtk.Skia

这是C#代码

 public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
        Paint();
    }
    private void Paint()
    {
        WriteableBitmap _wb = new WriteableBitmap(100,100);

        byte[] imageArray = new byte[_wb.PixelHeight * _wb.PixelWidth * 4];

        for (int i = 0; i < imageArray.Length; i += 4)
        {
            imageArray[i] = 0;
            imageArray[i + 1] = 0;
            imageArray[i + 2] = 255;
            imageArray[i + 3] = 255;
        }

        using (Stream stream = _wb.PixelBuffer.Asstream())
        {
            stream.Write(imageArray,imageArray.Length);

        }
        test.source = _wb;

    }
}

XAML代码

<Page
x:Class="test.Uno.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Image x:Name="test" VerticalAlignment="Top" />
</Grid>

解决方法

Skia尚不支持WriteableBitmap。这是related issue

更新(2020-09-18):Unable.UI 3.1.0-dev.364及更高版本中的Skia GTK / WPF可使用WriteableBitmap。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...