我正在尝试使用WriteableBitmap对象在UI上呈现一个红色框。该应用程序可以在UWP上正常工作:
在使用Gtk.Skia的Linux上,什么都没有显示(共享相同的代码):
这是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>
答案 0 :(得分:0)
Skia尚不支持WriteableBitmap。这是related issue。
更新(2020-09-18):Unable.UI 3.1.0-dev.364及更高版本中的Skia GTK / WPF可使用WriteableBitmap。