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 usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              22 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X