C# 将InkStroke的BoundingRect移动到0;0
我怎样才能将BoundingRect定义为坐标:X=0;Y=0? 我需要在Windows Universal App中将用户在C# 将InkStroke的BoundingRect移动到0;0,c#,.net,paint,win-universal-app,C#,.net,Paint,Win Universal App,我怎样才能将BoundingRect定义为坐标:X=0;Y=0? 我需要在Windows Universal App中将用户在InkCanvas上绘制的每个InkStroke单独保存为图像 为了保存最终图像,我使用Win2D,但这只是将裁剪的画布从保存到 private async Task SaveToImage(string id, InkStroke stroke, float width, float height) { CanvasDevice device = CanvasD
InkCanvas
上绘制的每个InkStroke
单独保存为图像
为了保存最终图像,我使用Win2D,但这只是将裁剪的画布从
保存到
private async Task SaveToImage(string id, InkStroke stroke, float width, float height)
{
CanvasDevice device = CanvasDevice.GetSharedDevice();
CanvasRenderTarget offscreen = new CanvasRenderTarget(device, width, height, 96);
using (CanvasDrawingSession ds = offscreen.CreateDrawingSession())
{
ds.Clear(Colors.Transparent);
ds.DrawInk(new InkStroke[] { stroke });
}
StorageFile f = await ApplicationData.Current.LocalFolder.CreateFileAsync(id + ".png", CreationCollisionOption.ReplaceExisting);
using (IRandomAccessStream output = await f.OpenAsync(FileAccessMode.ReadWrite))
{
await offscreen.SaveAsync(output, CanvasBitmapFileFormat.Png);
await output.FlushAsync();
}
}
我意识到这种方法可能是错误的 因此,我决定这样做:
- 通过Win2D将给定笔划绘制到屏幕外画布
- 屏幕外画布保存到InMemoryRandomAccessStream
- 将给定流裁剪为可写位图
- 打开StorageFile进行读/写操作
- 创建位图编码器并从WriteableBitmap设置像素数据