[英]How to save drawn ellipse over canvas as an image - Windows RT
我已经在画布上绘制了椭圆,现在如何将其另存为图像。 我知道您不能直接将画布另存为图像,也不能截图。 我正在使用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保存图像。 我将每个椭圆存储在inkmanager中,并调用SaveAsync方法,但是最后一个问题是图像为黑色,例如,如果我绘制红色椭圆,则保存的图像为黑色椭圆。
阅读此示例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商店应用目标8.0中不可用
Windows 8.1 API包括新的RenderTargetBitmap类,该类允许使用其RenderAsync方法呈现为位图。 您现在可以使用此方法链接,尽管它不适用于我需要的MediaElement :(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.