locked
Problem when using InkManager.LoadAsync() after setting pixel data RRS feed

  • Question

  • Hi All,

    In my drawing app using InkManager, I want to get pixel data of the canvas, do some changes and set the pixel data to the canvas.

    The only way I found is using InkManager.SaveAsync(IOutputStream outputStream) and LoadAsync(IInputStream inputStream). Here is my code:

    InMemoryRandomAccessStream saveStream = new InMemoryRandomAccessStream(); if (saveStream != null) await m_InkManager.SaveAsync(saveStream); saveStream.Seek(0); decoder = await BitmapDecoder.CreateAsync(saveStream); BitmapFrame bitmapFrame = await decoder.GetFrameAsync(0); double dpiX = bitmapFrame.DpiX; double dpiY = bitmapFrame.DpiY; uint wid = bitmapFrame.PixelWidth; uint hei = bitmapFrame.PixelHeight; // Get the pixels PixelDataProvider dataProvider = await bitmapFrame.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, new BitmapTransform(), ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb); byte[] pixels = dataProvider.DetachPixelData(); //for (int i = 0; i < pixels.Length; i++) //{ // pixels[i] = 0; //} InMemoryRandomAccessStream loadStream = new InMemoryRandomAccessStream(); loadStream.Size = 0; encoder = await BitmapEncoder.CreateAsync(Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId, loadStream); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, wid, hei, dpiX, dpiY, pixels);

    await encoder.FlushAsync(); await m_InkManager.LoadAsync(loadStream);

    For now the original pixel data has not been changed, but it throws an COMException, says:"Error HRESULT E_FAIL has been returned from a call to a COM component."

    Anybody can solve this, or has a better solution?

    Thank you.




    • Edited by Jakuri Thursday, September 26, 2013 10:10 AM
    Thursday, September 26, 2013 10:06 AM

Answers

  • Hi Jakuri,

    What is your actual goal here?

    The error is that the InkManager doesn't understand PNG files.

    It saves and loads Ink Serialized Format (ISF) metadata embedded in a GIF file. You can read out the GIF image to get a drawing of the path, but the InkManager won't pay attention to the pixel data when loading. It cares only about the ISF metadata.

    If you want to alter the InkStrokes in the InkManager then you need to modify the strokes themselves. You can do this by creating new strokes with an InkStrokeBuilder and then add them with InkManager.AddStroke.

    If you want to edit the ISF file directly the format is available here under the Microsoft Open Specification Promise .

    --Rob

    • Marked as answer by Jakuri Monday, September 30, 2013 9:26 AM
    Thursday, September 26, 2013 4:10 PM
    Moderator

All replies

  • Hi Jakuri,

    What is your actual goal here?

    The error is that the InkManager doesn't understand PNG files.

    It saves and loads Ink Serialized Format (ISF) metadata embedded in a GIF file. You can read out the GIF image to get a drawing of the path, but the InkManager won't pay attention to the pixel data when loading. It cares only about the ISF metadata.

    If you want to alter the InkStrokes in the InkManager then you need to modify the strokes themselves. You can do this by creating new strokes with an InkStrokeBuilder and then add them with InkManager.AddStroke.

    If you want to edit the ISF file directly the format is available here under the Microsoft Open Specification Promise .

    --Rob

    • Marked as answer by Jakuri Monday, September 30, 2013 9:26 AM
    Thursday, September 26, 2013 4:10 PM
    Moderator
  • Hi Rob,

    Thanks for your reply!

    I want to test our Anti-Aliasing algorithm on win8 tablet, I need to implement GetPixel(int x,int y) and SetPixel(int x,int y,unsigned int color) for it.

    I'm trying InkStrokeBuilder.

    Friday, September 27, 2013 6:16 AM