Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I get RGBA from a Stroke?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do I get RGBA from a Stroke?

    Stroke has a Brush, but that is the base class Brush, and so does not have a Color property. Same goes for Stroke.Pen. So how do I extract RGBA from a Stroke object?

    Is it useful for a Stroke to take any kind of Brush, or should that be a SolidColorBrush? (I do not really know all of the places a Stroke is used.)

    =====

    This question is just to see whether I am missing something. In my own code I can just always construct a Stroke with a SolidColorBrush, and the cast it back when I need to retrieve it.

    --EV
    Last edited by ETFVoyageur; 08-18-2015, 04:13 AM.

    #2
    Originally posted by ETFVoyageur View Post
    Stroke has a Brush, but that is the base class Brush, and so does not have a Color property. Same goes for Stroke.Pen. So how do I extract RGBA from a Stroke object?

    Is it useful for a Stroke to take any kind of Brush, or should that be a SolidColorBrush? (I do not really know all of the places a Stroke is used.)

    =====

    This question is just to see whether I am missing something. In my own code I can just always construct a Stroke with a SolidColorBrush, and the cast it back when I need to retrieve it.

    --EV
    DrawingAttributes property.

    Comment


      #3
      Originally posted by koganam View Post
      DrawingAttributes property.
      Intellisense says that Stroke does not have a DrawingAttributes property.

      --EV

      Comment


        #4
        Originally posted by ETFVoyageur View Post
        Intellisense says that Stroke does not have a DrawingAttributes property.

        --EV
        Are you using the Microsoft.Ink namespace, and have you referenced the microsoft.ink.dll?

        Comment


          #5
          In the System.Windows.Media namespace, only a SolidColorBrush will give you a color property. Stroke just takes a Brush which could use any type of brush to fill an area (LinearGradientBrush, etc).

          So to get the Color RGB from a Stroke, you can cast myStroke.Brush as a SolidColorBrush in order to get the Color property.

          Code:
          //NinjaTrader.Gui.Stroke from System.Windows.Media.Brushes
          Stroke myStroke = new Stroke(Brushes.Orchid);
          
          // System.Windows.Media.Color from Gui.Stroke.Brush as System.Windows.Media.SolidColorBrush
          Color myColor = ((SolidColorBrush)myStroke.Brush).Color;
          
          //	byte a = myColor.A;
          //	byte r = myColor.R;
          //	byte g = myColor.G;
          //	byte b = myColor.B;
          
          // create new System.Windows.Media.SolidColorBrush System.Windows.Media.Color.FromArgb();
          SolidColorBrush newBrush = new SolidColorBrush(Color.FromArgb(myColor.A, myColor.R, myColor.G, myColor.B));
          
          Print(newBrush.Color);
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by ETFVoyageur View Post
            Intellisense says that Stroke does not have a DrawingAttributes property.

            --EV
            Ignore me. That is Stroke from a different namespace. My mistake. I apologize.

            Comment


              #7
              Thanks folks. It sounds as if you are confirming that there is no better plan than the one from my original message: ensure that the Stroke is created with a SolidColorBrush and then cast as needed when it comes time to retrieve the RGBA.

              --EV

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by GussJ, 03-04-2020, 03:11 PM
              15 responses
              3,271 views
              0 likes
              Last Post xiinteractive  
              Started by Tim-c, Today, 02:10 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Taddypole, Today, 02:47 PM
              0 responses
              2 views
              0 likes
              Last Post Taddypole  
              Started by chbruno, 04-24-2024, 04:10 PM
              4 responses
              51 views
              0 likes
              Last Post chbruno
              by chbruno
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              10 responses
              403 views
              1 like
              Last Post beobast
              by beobast
               
              Working...
              X