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

时间:2020-09-16 15:57:06

标签: c# xaml cross-platform uno-platform

我正在尝试使用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, 0, 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>

1 个答案:

答案 0 :(得分:0)

Skia尚不支持WriteableBitmap。这是related issue

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