Note that there are some explanatory texts on larger screens.

plurals
  1. POStreamGeometry not getting rasterized when the Pen has DashStyle other than Null
    primarykey
    data
    text
    <p>I was trying to create a brush that draws a geometry. Everything worked fine until I tried to add Dashing to the shape.</p> <p>I found that when I create the geometry using Geometry.Parse, the dashed line appears correctly, but when I create it directly using StreamGeometryContext, nothing gets rendered. </p> <p>This is the code I'm using:</p> <pre><code>private void RenderGeometryAndSetAsBackground() { Point startPoint = new Point(3505961.52400725, 3281436.57325874); Point[] points = new Point[] { new Point(3503831.75515445,3278705.9649394), new Point(3503905.74802898,3278449.37713916), new Point(3507242.57331039,3276518.41148474), new Point(3507700.6914325,3276536.23547958), new Point(3510146.73449577,3277964.12812859), new Point(3509498.96473447,3278678.60178448), new Point(3507412.1889951,3277215.64022219), new Point(3504326.22698001,3278682.85514017), new Point(3506053.34789057,3281390.66371786)}; string geom = "M3505961.52400725,3281436.57325874L3503831.75515445,3278705.9649394 3503905.74802898,3278449.37713916 3507242.57331039,3276518.41148474 3507700.6914325,3276536.23547958 3510146.73449577,3277964.12812859 3509498.96473447,3278678.60178448 3507412.1889951,3277215.64022219 3504326.22698001,3278682.85514017 3506053.34789057,3281390.66371786"; //Geometry geometry = StreamGeometry.Parse(geom); StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext sgc = geometry.Open()) { sgc.BeginFigure(startPoint, false, true); foreach (Point p in points) { sgc.LineTo(p, true, true); } } Pen pen = new Pen(Brushes.Yellow, 3); pen.DashStyle = new DashStyle(new double[] { 30, 30 }, 0); //GeometryDrawing gd = new GeometryDrawing(null, pen, path.RenderedGeometry); GeometryDrawing gd = new GeometryDrawing(null, pen, geometry); DrawingBrush drawingBrush = new DrawingBrush(gd); DrawingBrush tile = drawingBrush.Clone(); tile.Viewbox = new Rect(0.5, 0, 0.25, 0.25); RenderTargetBitmap rtb = new RenderTargetBitmap(256, 256, 96, 96, PixelFormats.Pbgra32); var drawingVisual = new DrawingVisual(); using (DrawingContext context = drawingVisual.RenderOpen()) { context.DrawRectangle(tile, null, new Rect(0, 0, 256, 256)); } rtb.Render(drawingVisual); ImageBrush bgBrush = new ImageBrush(rtb); Background = bgBrush; } </code></pre> <p>When done that way, nothing is getting drawn. If I don't use dashing (or set the dashing to null) it works fine. It also works if I use the <code>StreamGeometry.Parse(geom)</code> and keeps the dashing.</p> <p>Trying to call <code>sgc.Close()</code> didn't help. Currently my only workaround is to call:</p> <pre><code>geometry = Geometry.Parse(geometry.ToString()); </code></pre> <p>which is not very nice...</p> <p>What am I missing? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload