You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maui Community Toolkit:DrawingView.GetImageStream如何初始化ImageLineOptions?

解决MAUI Community Toolkit 11.1.0中DrawingView.GetImageStream API变更问题

Maui Community Toolkit 11.1.0对DrawingView.GetImageStream方法做了API重构,移除了原有的多参数重载,改为仅接收ImageLineOptions实例作为参数。同时ImageLineOptions不再提供多参数构造函数,需要通过属性初始化器配置参数。

修改后的可用代码

替换原代码为以下实现,将原参数映射到ImageLineOptions的对应属性:

byte[] data = new byte[] { };
using (MemoryStream stream = new MemoryStream())
{
    var imageOptions = new ImageLineOptions
    {
        Lines = sigPadView.Lines,
        Size = new Size(sigPadView.Width, sigPadView.Height),
        BackgroundColor = Colors.Transparent
        // 如需自定义线条样式,可添加以下属性
        // LineColor = Colors.Black,
        // LineWidth = 2
    };

    using (Stream s = await DrawingView.GetImageStream(imageOptions))
    {
        s.CopyTo(stream);
        data = stream.ToArray();
    }
}

关键说明

  • ImageLineOptions的构造函数为无参,所有配置项需通过属性赋值完成
  • 原方法的lines、size、backgroundColor参数分别对应ImageLineOptions.Lines、ImageLineOptions.Size、ImageLineOptions.BackgroundColor属性
  • 若需要调整绘制线条的颜色、宽度等样式,可直接在ImageLineOptions中设置LineColor、LineWidth等属性

内容的提问来源于stack exchange,提问作者Shaboboo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:53:13