×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Best way to draw on an image smoothly?

    At present I'm using polyline to draw on a canvas and then saving it to the image..but the problem is the polyline is not smooth, I can see sharp edges in between.

    This is how I draw the polyline

    Code:
            void Touch_FrameReported(object sender, TouchFrameEventArgs e)
            {
    
                int pointsNumber = e.GetTouchPoints(DrawCanvas).Count;
                TouchPointCollection pointCollection = e.GetTouchPoints(DrawCanvas);
    
                for (int i = 0; i < pointsNumber; i++)
                {
    
                    if (pointCollection[i].Action == TouchAction.Down)
                    {
                        preXArray[i] = pointCollection[i].Position.X;
                        preYArray[i] = pointCollection[i].Position.Y;
                    }
                    if (pointCollection[i].Action == TouchAction.Move)
                    {
                        _undoButton.IsEnabled = true;
    
                        Polyline _polyline = new Polyline();
    
                        Point point1 = new Point(preXArray[i], preYArray[i]);
    
                        Point point2 = new Point(pointCollection[i].Position.X, pointCollection[i].Position.Y);
    
                        _polyline.Points.Add(point1);
                        _polyline.Points.Add(point2);
                        _polyline.Stroke = new SolidColorBrush(Colors.Black);
                        _polyline.StrokeThickness = 4;
                        _polyline.StrokeLineJoin = System.Windows.Media.PenLineJoin.Round;
    
                        DrawCanvas.Children.Add(_polyline);
    
                        preXArray[i] = pointCollection[i].Position.X;
                        preYArray[i] = pointCollection[i].Position.Y;
                    }
                }
            }
    Is there any other way to do it smoothly ?

  2. #2
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    105

    Re: Best way to draw on an image smoothly?

    Does it have to be a XAML polyline? You could draw directly onto a WriteableBitmap using WriteableBitmapEx extension tools...

    http://writeablebitmapex.codeplex.com/

    You can then use DrawLineAa, which is an anti-aliased version of DrawLine. There is no DrawPolylineAa like there is a DrawPolyline, but the source code is available and it might not take much effort to make a DrawPolylineAa using DrawLineAa's.

    *Edit: Now I see that you also need some thickness. That means you'll definitely have to rewrite some of the code to make it be more than one pixel width.

    An alternative is to create your own MLAA Effect in the Nokia Imaging SDK. (MLAA = morphological antialiasing). It's normally a post-rendering filter for 3D models... it makes the edges of models anti-aliased. You can apply this to certain images, too. Your best bet would be to translate HLSL code (DirectX shaders) to C# or C++.
    Last edited by leemcpherson; 2014-03-21 at 12:53.

  3. #3
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: Best way to draw on an image smoothly?

    I'll try and let you know the result

Similar Threads

  1. How to draw image over the background image
    By amit04.kumar in forum Symbian Media (Closed)
    Replies: 5
    Last Post: 2010-09-15, 16:15
  2. Draw image
    By symbi4n_programmer in forum Symbian
    Replies: 13
    Last Post: 2009-08-13, 09:36
  3. draw over image
    By Nourayn in forum Symbian Media (Closed)
    Replies: 28
    Last Post: 2009-05-06, 11:11
  4. how to draw PNG image?
    By chandra1234 in forum Symbian
    Replies: 2
    Last Post: 2008-08-01, 11:25
  5. How can I blit/draw a specific region of an Image to another Image?
    By tongits in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2006-04-29, 08:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×