Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I'm not understanding Color4

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

    I'm not understanding Color4

    I.m trying to create a series of custom colored brushes using Color4(float red, float green, float blue, float alpha)

    When I use RGB 0, 255, 0 I get green as expected.
    PHP Code:
    new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, new SharpDX.Color4(0f, 255f, 0f, 1f))​ 
    
    But when I use 15, 255, 0 I get yellow. It should be a little different shade of green.
    PHP Code:
    new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, new SharpDX.Color4(15f, 255f, 0f, 1f))​ 
    
    What am I doing wrong?​

    #2
    Hello cre8able,

    I wouldn't know the exact color mixes and you may need a bit of trial and error to get the exact shade you would like, but it may be easier to convert a windows media brush to a sharpdx brush.


    private System.Windows.Media.SolidColorBrush brushColor;
    private private SharpDX.Direct2D1.Brush dxBrush;

    In OnStateChange during State.DataLoaded:
    brushColor = Brushes.Green;

    In OnRenderTargetChanged():
    if (dxBrush != null)
    dxBrush.Dispose();

    if (RenderTarget != null)
    dxBrush = brushColor.ToDxBrush(RenderTarget);​

    Then the sharpDx brush can be used in OnRender() as needed.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks Chelsea
      I thought I had seen in other threads that is was best to not use ToDxBrush if I wasn't using the Windows media brush. I don't need it so was hoping to skip that step.

      My problem isn't getting the RGB numbers for the colors I want. It's just that when I put those values into the Color4() declaration, I don't get the RGB color that go with the RGB values unless 2 of the values are zero. I can get red, like in the example

      PHP Code:
      // create custom Brush using a "Red" SharpDX Color with "Alpha" (0.100f) transparency/opacity
      SharpDX.Direct2D1.SolidColorBrush transparentRedDXBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, new SharpDX.Color4(new SharpDX.Color3(220f, 0f, 0f), 0.100f));​ 
      
      I can also bet blue and green if I leave the other 2 values as 0. But when I put values in to make other colors, I get the wrong color as the output. I'm getting something wrong.

      My goal is to color code my indicator based on the strength of a certain signal. The stronger the signal, the darker the green. Using different transparencies doesn't work. I need different shades of green.

      I thought this would be the easiest way to do it

      Comment


        #4
        hey Chelsea... and anyone else who has this problem.

        in 2017, tradesmart posted the answer.



        the help file is correct in the values need to be float values for the color. But to a novice like me, I assumed that meant the RGB values just had to be floats.

        Instead you divide the RGB color by 255f. It would be EXTREMELY helpful if the NinjaScript guide explained that.

        Color4(float red, float green, float blue, float alpha) Initializes a new instance of the Color4 struct using float values for red, green, blue

        use Color4(R / 255f, G / 255f, B / 255f, opacity)


        huge thanks to #tradesmart



        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X