Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Adding Logo Causes Slowness

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

    Adding Logo Causes Slowness

    When using this code found here It causes my indicator to destabilize and Ninjatrader stops working every now and then. Any way to avoid or correct this?




    Code:
    public override void OnRenderTargetChanged()
    {
    myBitmap = LoadBitmapFromContentFile(System.IO.Path.Combine(N injaTrader.Core.Globals.UserDataDir, "cat.png"));
    }
    
    protected override void OnRender(NinjaTrader.Gui.Chart.ChartControl chartControl, NinjaTrader.Gui.Chart.ChartScale chartScale)
    {
    
    if (Bars == null || Bars.Instrument == null || myBitmap == null)
    return;
    
    RenderTarget.DrawBitmap(myBitmap, new SharpDX.RectangleF((float)ChartPanel.W - 1650, (float)ChartPanel.H -700, 150, 150), 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
    
    }
    
    private SharpDX.Direct2D1.Bitmap LoadBitmapFromContentFile(string filePath)
    {
    if (RenderTarget == null) return null;
    SharpDX.Direct2D1.Bitmap newBitmap;
    
    // Neccessary for creating WIC objects.
    SharpDX.WIC.ImagingFactory imagingFactory = new SharpDX.WIC.ImagingFactory();
    SharpDX.IO.NativeFileStream fileStream = new SharpDX.IO.NativeFileStream(filePath, SharpDX.IO.NativeFileMode.Open, SharpDX.IO.NativeFileAccess.Read);
    
    // Used to read the image source file.
    SharpDX.WIC.BitmapDecoder bitmapDecoder = new SharpDX.WIC.BitmapDecoder(imagingFactory, fileStream, SharpDX.WIC.DecodeOptions.CacheOnDemand);
    
    // Get the first frame of the image.
    SharpDX.WIC.BitmapFrameDecode frame = bitmapDecoder.GetFrame(0);
    
    // Convert it to a compatible pixel format.
    SharpDX.WIC.FormatConverter converter = new SharpDX.WIC.FormatConverter(imagingFactory);
    converter.Initialize(frame, SharpDX.WIC.PixelFormat.Format32bppPRGBA);
    
    // Create the new Bitmap1 directly from the FormatConverter.
    if (RenderTarget != null) newBitmap = SharpDX.Direct2D1.Bitmap.FromWicBitmap(RenderTarge t, converter);
    else newBitmap = null;
    SharpDX.Utilities.Dispose(ref bitmapDecoder);
    SharpDX.Utilities.Dispose(ref fileStream);
    SharpDX.Utilities.Dispose(ref imagingFactory);
    
    return newBitmap;
    }

    #2
    Hello,

    Do you see the same if you use the sample from the following post?



    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Yes that's where I got it from...

      Comment


        #4
        Hello r3n3v,

        Did you make modifications to that script? The code alone does not help to know what may be happening, do you see the same problem using the unmodified sample?

        This could also relate to the image being used, have you tried another image?

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          It's exact. The only thing that changed was the image. Is there a specific type we should be using?

          Comment


            #6
            Hello r3n3v,

            Did you try the samples original image or a different one than you have used? It may be the image causing the problem if the original sample works fine. There is no specific documentation for the code you have used, that is an external library called sharpdx which NinjaTrader leverages for rendering. The linked sample is a generic sample found for use with sharpDX and has some modifications made to adapt to the NinjaTrader overrides.


            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            9 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            14 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Yesterday, 08:42 PM
            0 responses
            11 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Yesterday, 07:51 PM
            0 responses
            13 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,983 views
            3 likes
            Last Post jhudas88  
            Working...
            X