Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Odd-width lines draw incorrectly (WPF Feb CTP)

 
 
Old 05-18-2006   #1 (permalink)
Mike Strobel


 
 

Odd-width lines draw incorrectly (WPF Feb CTP)

I've run into an interesting problem with the February CTP of the WPF. I
have created a FrameworkElement that serves as a visual host for many
DrawingVisuals. I draw to each of those visuals manually using RenderOpen()
and the Draw() methods. However, when I attempt to draw a straight
horizontal or veritcal line that is 1pt thick, the line gets interpolated
across two pixels. The same happens with any line of an odd thickness (3pt,
5pt, etc). However, lines of an even thickness draw perfectly, and I have
taken screenshots and zoomed in just to make sure. Now, if I set the Offset
property of the visuals to a vector <0.5, 0.5>, the odd lines draw correctly,
but the even lines get interpolated.

I am not using any transforms, and I have tried setting the host window's
SnapsToDevicePixels property to True, but to no avail. I did not have this
problem when I worked on a previous project using the January CTP. Can
anyone offer a cause or a possible workaround?

Cheers,
Mike

My System SpecsSystem Spec
Old 05-19-2006   #2 (permalink)
Adam Smith [MS]


 
 

Re: Odd-width lines draw incorrectly (WPF Feb CTP)

Fundamentally, this is simply how anti-aliased rendering has to appear in
order to render the content you're rendering. If you draw a 1px line from
0,10 to 10,10, you've just filled the area from 0,9.5 to 10,10.5. So, if
your local coordinate space happens to place y=9.5 on the edge of a pixel,
you'll get one a physical pixel line, while if it falls at the center of a
pixel you now have two rows of pixels each with 50% coverage. Of course,
it's only this simple if your display is 96 DPI - if you're at 133dpi, then
your "1px" line is actually ~1 1/3 device pixels thick so you'll always have
some bleed.

You *can* use pixel snapping to address this, but because you're drawing
this yourself the "magic" layout-based pixel snapping (SnapsToDevicePixels)
won't help. Instead you'll need to use PushGuidelineSet:

http://windowssdk.msdn.microsoft.com...1_2b99ec42.asp

The risk with this, though, is that you may get lines of 1 thickness, yes,
but other lines may be snapped to 2 pixels (on higher than 96 DPI monitors
this becomes more likely).

-Adam Smith [MS]

"Mike Strobel" <Mike Strobel@discussions.microsoft.com> wrote in message
news:408F8D39-E764-4B42-AE51-DF680621B42F@microsoft.com...
> I've run into an interesting problem with the February CTP of the WPF. I
> have created a FrameworkElement that serves as a visual host for many
> DrawingVisuals. I draw to each of those visuals manually using
> RenderOpen()
> and the Draw() methods. However, when I attempt to draw a straight
> horizontal or veritcal line that is 1pt thick, the line gets interpolated
> across two pixels. The same happens with any line of an odd thickness
> (3pt,
> 5pt, etc). However, lines of an even thickness draw perfectly, and I have
> taken screenshots and zoomed in just to make sure. Now, if I set the
> Offset
> property of the visuals to a vector <0.5, 0.5>, the odd lines draw
> correctly,
> but the even lines get interpolated.
>
> I am not using any transforms, and I have tried setting the host window's
> SnapsToDevicePixels property to True, but to no avail. I did not have
> this
> problem when I worked on a previous project using the January CTP. Can
> anyone offer a cause or a possible workaround?
>
> Cheers,
> Mike



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Corel draw x13 Software
Draw Pad Issues Windows Live
BUG: Redirecting function contents to a file truncates function lines at the width of the console PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46