locked
Stroke thickness for WriteableBitmap in C# windows 8 metro app RRS feed

  • Question

  • Hi,

    Shape obj;

    InkStroke stroke = (InkStroke)obj.Tag;

    if(null != stroke)

    {

      var renderingStrokes = stroke.GetRenderingSegments();

      var prvPosition = renderingStrokes[0].Position;

      foreach(var renderStroke in renderingStrokes)

      {

         drawingbmp.DrawBezier((int)prvPosition.X, (int)prvPosition.Y,

                               (int)renderStroke.BezierControlPoint1.X,

                               (int)renderStroke.BezierControlPoint1.Y,

                               (int)renderStroke.BezierControlPoint2.X,

                               (int)renderStroke.BezierControlPoint2.Y,

                                  (int)renderStroke.Position.X, (int)renderStroke.Position.Y,

                                ((SolidColorBrush)obj.Stroke).Color);

                                prvPosition = renderStroke.Position;

                            }

                       }

                  }

     BitmapPixelFormatbitmapPixelFormat = BitmapPixelFormat.Bgra8;

    BitmapAlphaModebitmapAlphaMode = BitmapAlphaMode.Ignore;

    doubledpiX = 96.0;

    doubledpiY = 96.0;

    encoder.SetPixelData(
    bitmapPixelFormat,bitmapAlphaMode,                                                             

                         (uint)this.Width, (uint)this.Height, dpiX, dpiY,

                               drawingbmp.ToByteArray());

    await encoder.FlushAsync();                         

                           

    Using above code block drawing writablebitmap from shape object which has strokethickness.

    but while saving file as jpeg color only reflects but not the strokethickness.

    anybody has idea how to maintain strokethickness?

                           

                           



    • Edited by cauveri Thursday, August 29, 2013 5:57 AM
    Thursday, August 29, 2013 5:55 AM

Answers

  • DrawBezier is not a standard function on WriteableBitmap. Are you using a 3rd party control library such as WritableBitmapEx?

    You can get the size and shape of the pen tip from the InkStroke's DrawingAttributes. See How to render ink data for an JavaScript sample of how to read the stroke information. That will be essentially the same in C#, but you'll need to convert the actual rendering to use the control you are targeting. You'll need to reference the docs for that control to find how to set stroke thickness on it.

    --Rob

    • Marked as answer by Anne Jing Monday, September 9, 2013 1:15 AM
    Thursday, August 29, 2013 2:51 PM
    Moderator

All replies

  • DrawBezier is not a standard function on WriteableBitmap. Are you using a 3rd party control library such as WritableBitmapEx?

    You can get the size and shape of the pen tip from the InkStroke's DrawingAttributes. See How to render ink data for an JavaScript sample of how to read the stroke information. That will be essentially the same in C#, but you'll need to convert the actual rendering to use the control you are targeting. You'll need to reference the docs for that control to find how to set stroke thickness on it.

    --Rob

    • Marked as answer by Anne Jing Monday, September 9, 2013 1:15 AM
    Thursday, August 29, 2013 2:51 PM
    Moderator
  • Yes,I'm using WritableBitmapEx.

    I will check with sample you provided.

    Thanks :)

    Monday, September 2, 2013 5:03 AM