Pre loader

Image Point Marker in Code

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

Is it possible to render an image from file as a point marker in the code?

Version
4
  • You must to post comments
0
0

Hi there,

Do you have a screenshot of what you are trying to achieve? It’s not clear from the question what you need and why.

You can render anything as a PointMarker, using our SpritePointMarker API.

It won’t let you draw dynamic images though. That’s a little bit harder. But probably not impossible.

Please comment more on your requirements and we might be able to help.

Best regards,
Andrew

  • Aysan Afrand
    Andrew, Sorry, i wasn’t clear. I have a CustomFastLineRenderableSeries class which inherits from FastLineRenderableSeries. In this class i go over all the points and draw a different shape for each point in InternalDraw function using renderContext.Draw. I saw SpritePointMarker in scichart documentation, we can assign a template to this class and draw any point marker. I would like to see if it is possible to take advantage of this class in InternalDraw function and put an image as a point marker. Let me know if it’s still not clear. Thanks.
  • You must to post comments
0
0

Hi Aysan,

Thank you for clarification. Yes, it is possible to achieve this using SpritePointMarker. However, please be aware that it creates a sprite once and caches it. So if you want to have different PointMarkers, you will need to override the default behavior. Here is the current implementation of the SpritePointMarker:

public class SpritePointMarker : BitmapSpriteBase
{
    private PointMarker _cachedMarker;

    protected override void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        Dispose();

        base.OnPropertyChanged(d, e);
    }

    protected override ISprite2D CreateSprite(IRenderContext2D context, Color strokeColor, Color strokeBrush)
    {
        if (_cachedMarker == null)
        {
            _cachedMarker = PointMarker.CreateFromTemplate(PointMarkerTemplate, DataContext);
        }

        return context.CreateSprite(_cachedMarker);
    }

    protected override void RenderToCache(IRenderContext2D context, IPen2D strokePen, IBrush2D fillBrush)
    {
        throw new NotImplementedException();
    }
}

The call of the Dispose() method in OnPropertyChanged() releases internally cached BitmapSprite, which was created in the CreateSprite(..).

The RenderToCache(..) is called by the base implementation of CreateSprite(..) in BitmapSpriteBase and is intended to draw directly on bitmap using IRenderContext2D. It isn’t required here, so left not implemented.

Hope this helps,

Best regards,
Yuriy

  • You must to post comments
0
0

Thanks Yuriy.

I think i’m good with using current implementation of SpritePointMarker.

This is my code snippet trying to use SpritePointMarker in InternalDraw of FastLineRenderableSeries:

                if (SomeCondition)
                {
                    var xaml = "<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>" +
                               "<Image Source=\"ship.png\" Width=\"20\" Height=\"20\"/>" +  "</ControlTemplate>";
                    var p = new SpritePointMarker() {PointMarkerTemplate = (ControlTemplate)XamlReader.Parse(xaml) };

                    Point[] center = { orig };
                    p.Draw(renderContext, center);
                }

Does it make sense to use SpritePointMarker like the code above?
I’m not seeing any output yet, so guessing something not quite right.

  • You must to post comments
Showing 3 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