How to replace DrawClosedCurve / FillClosedCurve when moving from WinForms (GDI+) to WPF?












0














I've got an array of points (X,Y) which constitute a convex hull (a simple, irregularly shaped contour). Rather than rendering a polygon with straight edges, I want to render them with an approximate "smoothly curved" contour that passes through all of these points.



In WinForms/GDI+, this could be accomplished with the Graphics.DrawClosedCurve or Graphics.FillClosedCurve methods. There does not appear to be an equivalent in WPF.



I've looked into drawing using things like Path and BezierSegment, but I'm not sure if (and how) these can be used to generate a continuous closed curve, given a set of points. It appears that to do this, I'd perhaps have to generate a set of control points based on my contour as an intermediate step?



I have tried using the GDI+ methods to render onto a System.Drawing.Bitmap and then displaying that in the WPF application. This works, but the performance (particularly the conversion from System.Drawing.Bitmap to BitmapSource) is poor and not sufficient for the application. This is why I'm looking for a pure WPF solution.



Has anyone been able to draw a closed curve based off a set of points in WPF?










share|improve this question



























    0














    I've got an array of points (X,Y) which constitute a convex hull (a simple, irregularly shaped contour). Rather than rendering a polygon with straight edges, I want to render them with an approximate "smoothly curved" contour that passes through all of these points.



    In WinForms/GDI+, this could be accomplished with the Graphics.DrawClosedCurve or Graphics.FillClosedCurve methods. There does not appear to be an equivalent in WPF.



    I've looked into drawing using things like Path and BezierSegment, but I'm not sure if (and how) these can be used to generate a continuous closed curve, given a set of points. It appears that to do this, I'd perhaps have to generate a set of control points based on my contour as an intermediate step?



    I have tried using the GDI+ methods to render onto a System.Drawing.Bitmap and then displaying that in the WPF application. This works, but the performance (particularly the conversion from System.Drawing.Bitmap to BitmapSource) is poor and not sufficient for the application. This is why I'm looking for a pure WPF solution.



    Has anyone been able to draw a closed curve based off a set of points in WPF?










    share|improve this question

























      0












      0








      0







      I've got an array of points (X,Y) which constitute a convex hull (a simple, irregularly shaped contour). Rather than rendering a polygon with straight edges, I want to render them with an approximate "smoothly curved" contour that passes through all of these points.



      In WinForms/GDI+, this could be accomplished with the Graphics.DrawClosedCurve or Graphics.FillClosedCurve methods. There does not appear to be an equivalent in WPF.



      I've looked into drawing using things like Path and BezierSegment, but I'm not sure if (and how) these can be used to generate a continuous closed curve, given a set of points. It appears that to do this, I'd perhaps have to generate a set of control points based on my contour as an intermediate step?



      I have tried using the GDI+ methods to render onto a System.Drawing.Bitmap and then displaying that in the WPF application. This works, but the performance (particularly the conversion from System.Drawing.Bitmap to BitmapSource) is poor and not sufficient for the application. This is why I'm looking for a pure WPF solution.



      Has anyone been able to draw a closed curve based off a set of points in WPF?










      share|improve this question













      I've got an array of points (X,Y) which constitute a convex hull (a simple, irregularly shaped contour). Rather than rendering a polygon with straight edges, I want to render them with an approximate "smoothly curved" contour that passes through all of these points.



      In WinForms/GDI+, this could be accomplished with the Graphics.DrawClosedCurve or Graphics.FillClosedCurve methods. There does not appear to be an equivalent in WPF.



      I've looked into drawing using things like Path and BezierSegment, but I'm not sure if (and how) these can be used to generate a continuous closed curve, given a set of points. It appears that to do this, I'd perhaps have to generate a set of control points based on my contour as an intermediate step?



      I have tried using the GDI+ methods to render onto a System.Drawing.Bitmap and then displaying that in the WPF application. This works, but the performance (particularly the conversion from System.Drawing.Bitmap to BitmapSource) is poor and not sufficient for the application. This is why I'm looking for a pure WPF solution.



      Has anyone been able to draw a closed curve based off a set of points in WPF?







      c wpf gdi+ bezier curve






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 19:21









      Kohanz

      1,0541029




      1,0541029
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:




          • Host a native window within your WPF window and perform all your drawing on it.

          • Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.






          share|improve this answer





















          • Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
            – Kohanz
            Nov 22 at 21:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437012%2fhow-to-replace-drawclosedcurve-fillclosedcurve-when-moving-from-winforms-gdi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:




          • Host a native window within your WPF window and perform all your drawing on it.

          • Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.






          share|improve this answer





















          • Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
            – Kohanz
            Nov 22 at 21:23
















          1














          Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:




          • Host a native window within your WPF window and perform all your drawing on it.

          • Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.






          share|improve this answer





















          • Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
            – Kohanz
            Nov 22 at 21:23














          1












          1








          1






          Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:




          • Host a native window within your WPF window and perform all your drawing on it.

          • Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.






          share|improve this answer












          Unfortunately, there is no single-method equivalent to DrawClosedCurve in WPF, even though it's been requested. So you are left with at least two options:




          • Host a native window within your WPF window and perform all your drawing on it.

          • Implement your own cardinal spline drawing. You are on the right track with Bezier segments. However, there are existing implementations of it you can look at out there.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 20:40









          mnistic

          6,9781820




          6,9781820












          • Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
            – Kohanz
            Nov 22 at 21:23


















          • Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
            – Kohanz
            Nov 22 at 21:23
















          Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
          – Kohanz
          Nov 22 at 21:23




          Thank you so much! Your answer was exactly the information I needed. Particularly the last link.
          – Kohanz
          Nov 22 at 21:23


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437012%2fhow-to-replace-drawclosedcurve-fillclosedcurve-when-moving-from-winforms-gdi%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu