最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Maui Community toolkit - DrawingView.GetImageStream - how to initialize ImageLineOptions? - Stack Overflow

programmeradmin1浏览0评论

We recently updated to the community toolkit 11.1.0

Now my DrawingView can't seem to get image from stream, the arguments have changed, and I can't get it to work correctly anymore.

Original working code:

 byte[] data = new byte[] { };
 using (MemoryStream stream = new MemoryStream())
 {

     using (Stream s = await DrawingView.GetImageStream(sigPadView.Lines, new Size(sigPadView.Width, sigPadView.Height), Colors.Transparent)) 
     {
         s.CopyTo(stream);
         data = stream.ToArray();
     }
 }

Now it is telling me it can't cast the lines from the DrawingView control to double? Looks like the arguments for DrawingView.GetImageStream() have changed, and now it wants an ImageLineOptions object.

Taking a look at ImageLineOptions, the constructor seems to take the same parameters as the DrawingView.GetImageStream() did, but I cannot seem to initialize this object. Visual studio just tells me ImageLineOptions constructor doesn't take 3 or 4 parameters, and IntelliSense refuses to show me the various overrides.

Does anyone know how to get this code working again? The documentation hasn't been updated to reflect this change yet.

We recently updated to the community toolkit 11.1.0

Now my DrawingView can't seem to get image from stream, the arguments have changed, and I can't get it to work correctly anymore.

Original working code:

 byte[] data = new byte[] { };
 using (MemoryStream stream = new MemoryStream())
 {

     using (Stream s = await DrawingView.GetImageStream(sigPadView.Lines, new Size(sigPadView.Width, sigPadView.Height), Colors.Transparent)) 
     {
         s.CopyTo(stream);
         data = stream.ToArray();
     }
 }

Now it is telling me it can't cast the lines from the DrawingView control to double? Looks like the arguments for DrawingView.GetImageStream() have changed, and now it wants an ImageLineOptions object.

Taking a look at ImageLineOptions, the constructor seems to take the same parameters as the DrawingView.GetImageStream() did, but I cannot seem to initialize this object. Visual studio just tells me ImageLineOptions constructor doesn't take 3 or 4 parameters, and IntelliSense refuses to show me the various overrides.

Does anyone know how to get this code working again? The documentation hasn't been updated to reflect this change yet.

Share asked Mar 7 at 17:00 ShabobooShaboboo 1,5931 gold badge18 silver badges39 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Easiest conversion would be to pass ImageLineOptions, i.e.

using (Stream s = await DrawingView.GetImageStream(ImageLineOptions.FullCanvas(sigPadView.Lines, new Size(sigPadView.Width, sigPadView.Height), Colors.Transparent.AsPaint(), new Size(sigPadView.Width, sigPadView.Height)))) 
     {
         s.CopyTo(stream);
         data = stream.ToArray();
     }

FullCanvas needs 2 sizes, so you might want to adopt the desiredSize

/// <param name="lines">The lines that will be rendered in the resulting image.</param>
/// <param name="desiredSize">The desired dimensions of the generated image. The image will be resized proportionally.</param>
/// <param name="background">The background <see cref="Paint"/> to apply to the output image.</param>
/// <param name="canvasSize">The actual size of the canvas being displayed.</param>
发布评论

评论列表(0)

  1. 暂无评论