Skip to main content

Microsoft Silverlight

Unanswered Question Problem in drawing 1px line in InkPresenter with StrokeRSS Feed

(0)

rorbbin
rorbbin

Member

Member

2 points

5 Posts

Problem in drawing 1px line in InkPresenter with Stroke

 I have a problem in drawing 1px line in InkPresenter using Stroke. I doubt there is something inperfect with its mechanism in rendering line. I have set my stroke's DrawingAttributes as follow:

             

            newStroke.DrawingAttributes.Color = Colors.Black;
newStroke.DrawingAttributes.Height = 0.5; // 1 and 2 to be test
newStroke.DrawingAttributes.Width = 0.5;
newStroke.DrawingAttributes.OutlineColor = Colors.Transparent;
 

and I have get the result as follow picture compare with the Windows paint:

 

if not displayed, image url:Show image

As shown in picture, silverlight renders the 0.5px, 1px and 2px lines with no diffirence but color changing from lightgray to black. What I want is the line rendered in paint as lower part of the picture. How Can I solve this problem. The following is the code I written:

Page.xaml

 

<UserControl x:Class="HelloWorld.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="406" Height="404">
<Grid x:Name="LayoutRoot" Background="Black">

<InkPresenter x:Name="inkPresenter" Width="400" Height="400"
Background="White"
MouseLeftButtonDown="inkPresenter_MouseLeftButtonDown"
MouseLeftButtonUp="inkPresenter_MouseLeftButtonUp"
MouseMove="inkPresenter_MouseMove"/>
</Grid>
</UserControl>

  Page.xaml.cs

 

public partial class Page : UserControl
{
InkPresenter curInkPre = null;
Cursor oldCursor = Cursors.Arrow;
Stroke newStroke = null;
public Page()
{
InitializeComponent();
SetBoundary(inkPresenter);
}


private void inkPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
curInkPre = e.OriginalSource as InkPresenter;
curInkPre.CaptureMouse();
oldCursor = curInkPre.Cursor;
curInkPre.Cursor = Cursors.Stylus;
newStroke = new Stroke();
newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(curInkPre));
newStroke.DrawingAttributes.Color = Colors.Black;
newStroke.DrawingAttributes.Height = 2;
newStroke.DrawingAttributes.Width = 2;
newStroke.DrawingAttributes.OutlineColor = Colors.Transparent;
curInkPre.Strokes.Add(newStroke);
}

private void inkPresenter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
newStroke = null;
InkPresenter ink = e.OriginalSource as InkPresenter;
ink.Cursor = oldCursor;
}

private void inkPresenter_MouseMove(object sender, MouseEventArgs e)
{
if (newStroke != null)
{
newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(curInkPre));
}
}
private void SetBoundary(InkPresenter ink)
{
RectangleGeometry rectGeo = new RectangleGeometry();
rectGeo.Rect = new Rect(0, 0, ink.ActualWidth, ink.ActualHeight);
ink.Clip = rectGeo;
}
}
  Any one can solve my problem. Thanks in advance.

StefanWick
StefanWick

Contributor

Contributor

2864 points

438 Posts

Microsoft

Re: Problem in drawing 1px line in InkPresenter with Stroke

This picture didn't come through. Also the URL didn't work for me. Can you update this?

Thanks, Stefan Wick

Microsoft Silverlight | http://blogs.msdn.com/swick/

rorbbin
rorbbin

Member

Member

2 points

5 Posts

Re: Problem in drawing 1px line in InkPresenter with Stroke

 It works fine as I click. If you can tell me your email and I wil sent it to you.

StefanWick
StefanWick

Contributor

Contributor

2864 points

438 Posts

Microsoft

Re: Problem in drawing 1px line in InkPresenter with Stroke

Please send it to swick at microsoft.com.

Thanks, Stefan Wick

Microsoft Silverlight | http://blogs.msdn.com/swick/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities