0

I have a question about saving ink file (including ink's meta data file .gif) in uwp.

(ink means that something user drawn)

Currently, I can only save the range of ink that it's part of the inkcanvas, not full - screen inkcanvas

inkcanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream);

This way only saves the ink, not inkcanvas's full-screen.

I want to show the ink and full-screen to user, so I need a ink and full-screen

Is this way possible?

Please any help! Thanks

Kay
  • 173
  • 14
  • Do you have the idea to use the [RenderTargetBitmap](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.media.imaging.rendertargetbitmap) to render the ink canvas as an image then dispaly it? – Breeze Liu - MSFT Jul 04 '18 at 03:09
  • @BreezeLiu-MSFT but you cannot restore the strokers to an InkCanvas later, the meta data is lost when rendering to bitmap. – kennyzx Jul 05 '18 at 09:37
  • Maybe you could save the strokes and the render image respectively. – Breeze Liu - MSFT Jul 09 '18 at 08:23
  • @BreezeLiu-MSFT Yes I saved them seperately. Because I need each file – Kay Jul 10 '18 at 00:38

1 Answers1

1

A workaround for this is drawing 2 invisible dots to the canvas, one at the upper-left corner, one at the bottom-right corner.

Add them before the call to StrokeContainer.SaveAsync.

private void AddInvisibleDotsAtCorners()
{
    var inkStrokeBuilder = new InkStrokeBuilder();
    var stroke1 = inkStrokeBuilder.CreateStrokeFromInkPoints(
        new InkPoint[] 
        {
            new InkPoint(new Point(0, 0), 0.0f)
        }, System.Numerics.Matrix3x2.Identity);

    var stroke2 = inkStrokeBuilder.CreateStrokeFromInkPoints(
        new InkPoint[]
        {
            new InkPoint(new Point(inkCanvas.ActualWidth, inkCanvas.ActualHeight), 0.0f)
        }, System.Numerics.Matrix3x2.Identity);
    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke1);
    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke2);
}

then remove them after the call StrokeContainer.SaveAsync is completed.

kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • Thanks! that's really helpful! It's hard to apply to my code, but your idea really good for me Thank you. – Kay Jul 03 '18 at 07:27