Pre loader

Rendering a bitmap in an ASP.net core API type project

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

We’re developing an extra web based front end for what was until now a monolithic WPF .Net 4.72 application and want to add a small service that we can host a REST API, that when given a GUID, can render the data into a scichart exported bitmap.

My plan was to use ASP.NET core to do this as the rest of web application will be done using this, but although I can install the scichart package, I can’t find a way to reference the Presentation Core dlls (needed for amongst other things the colors and content control stuff).

The project sdk is Microsoft.NET.Sdk.Web, but I can’t figure out how to do this.

Version
6.3
  • You must to post comments
0
0

Hello. Your article helped me a lot. I am currently writing my master’s thesis. I have difficulty with this. I was advised to find masters assignment writing. I found Assignment Masters service. These guys helped me a lot. Professional writers were always ready to help.

  • You must to post comments
0
0

It turns out simpler than I thought I needed to add the following to the project file:

FrameworkReference Include=”Microsoft.WindowsDesktop.App.Wpf

This does mean you will be restricted to running the service on a windows machine though so be aware of that.

Then because the SciChart stuff needs to run in an STA thread (the asp.net core project is MTA). You need to run it in a separate thread in the Get of the controller:


[HttpGet]
public IActionResult Get()
{

        byte[] bytes = null;
        Thread newWindowThread = new Thread(new ThreadStart(() =>
        {
            var bs = CreatChart();
            var encoder = new PngBitmapEncoder();



            using (MemoryStream stream = new MemoryStream())
            {
                encoder.Frames.Add(BitmapFrame.Create(bs));
                encoder.Save(stream);
                bytes = stream.ToArray();
                stream.Close();
            }

        }));

        // set the apartment state  
        newWindowThread.SetApartmentState(ApartmentState.STA);

        // make the thread a background thread  
        newWindowThread.IsBackground = true;

        // start the thread  
        newWindowThread.Start();
        newWindowThread.Join();

        return File(bytes, "image/png");

    }
}

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies