【问题标题】:How to save drawn ellipse over canvas as an image - Windows RT如何将画布上绘制的椭圆保存为图像 - Windows RT
【发布时间】:2013-07-31 19:21:53
【问题描述】:

我已经在画布上绘制了椭圆,现在如何将它保存为图像。我知道你不能直接将画布保存为图像,也不能截图。我在 C#/xaml 中工作。下面是我在画布上绘制椭圆的代码。

private void canvasDraw_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        if (drawing)
        {
            PointerPoint current = e.GetCurrentPoint((UIElement)sender);
           // Line line = new Line() { X1 = start.Position.X, Y1 = start.Position.Y, X2 = current.Position.X, Y2 = current.Position.Y };
            //line.Stroke = new SolidColorBrush(Colors.Black);
            Ellipse circle = new Ellipse();
            circle.SetValue(Canvas.LeftProperty, current.Position.X);
            circle.SetValue(Canvas.TopProperty, current.Position.Y);
            circle.Height = 20;
            circle.Width = 20;
            circle.Fill = currentBrush;
            circle.Opacity = 0.7;
            circle.SetValue(Canvas.ZIndexProperty,1);
            canvasDraw.Children.Add(circle);

        }
    }

编辑:我可以使用 InkManager 保存图像。我将每个 Ellipse 存储在 inkmanager 中并调用 SaveAsync 方法,但最后一个问题是图像是黑色的,例如,如果我绘制红色椭圆,则保存的图像有黑色椭圆。

【问题讨论】:

  • 我认为你需要在这里澄清你的标签。而不是wpfxaml,也许你的意思是winrt-xaml?而不是windows-rt,也许你的意思是windows-runtime
  • 我已经更新了我的标签,谢谢。
  • 这不是上述问题的重复问题,因为它是针对 win-rt 而不是 wpf
  • 您可以查看相关问题的答案stackoverflow.com/questions/11627830/…

标签: c# windows-8 windows-runtime winrt-xaml


【解决方案1】:

阅读这个例子http://blogs.msdn.com/b/swick/archive/2007/12/02/rendering-ink-and-image-to-a-bitmap-using-wpf.aspx

网站代码摘录:

// render InkCanvas' visual tree to the RenderTargetBitmap
RenderTargetBitmap targetBitmap =
    new RenderTargetBitmap((int)inkCanvas1.ActualWidth,
                           (int)inkCanvas1.ActualHeight,
                           96d, 96d,
                           PixelFormats.Default);
targetBitmap.Render(inkCanvas1);

// add the RenderTargetBitmap to a Bitmapencoder
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(targetBitmap));

// save file to disk
FileStream fs = File.Open(fileName, FileMode.OpenOrCreate);
encoder.Save(fs);

【讨论】:

  • RenderTargetBitmap 在 windows-rt 中不可用
【解决方案2】:

是的RenderTargetBitmap它在windows store app target 8.0中不可用

Windows 8.1 API 包括新的 RenderTargetBitmap 类,该类允许使用其 RenderAsync 方法呈现位图。 您现在可以使用此方法 link 虽然它不适用于我需要的 MediaElement :(

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2023-03-23
    • 2011-01-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    相关资源
    最近更新 更多