Pre loader

Generating a UIImage from a SCIChartSurface

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


I’m try to generate a UIImage from a SCIChartSurface into a graphic context using the code below from a view that is not displayed on the screen. The image created is pure black, which indicates it did not draw. If I display the graph in a view on the devices screen, the graph draws correctly.

UIGraphicsBeginImageContextWithOptions(self.chart.bounds.size, NO, 0.0);
[self.chart drawViewHierarchyInRect:self.chart.bounds afterScreenUpdates:YES];
UIImage *chartImage = UIGraphicsGetImageFromCurrentImageContext();

Are there any special steps that are needed to draw into a graphic context?

  • You must to post comments
Best Answer

Update: In SciChart iOS v4 and above we now have a function for screenshots built in

Please see exportToUIImage and exportToUIImageWithRect in the SciChart iOS documentation.

  • You must to post comments

Outdated Answer

this answer has been superceded by exportToUIImage and exportToUIImageWithRect functions on SciChartSurface

We have a short code sample below to export a screenshot of the chart to UIImage:

Because of using OpenGL as the main drawing framework, you might have some issues when capturing the screen with a SciChartSurface on it. But as a workaround here is a function for you to try:

-(UIImage*) screenshotFromView:(UIView*)view {
    CGSize size = CGSizeMake(view.frame.size.width, view.frame.size.height);
    UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.mainScreen.scale);
    CGRect rec = CGRectMake(0, 0, view.frame.size.width,view.frame.size.height);
    [view drawViewHierarchyInRect:rec afterScreenUpdates:YES];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    return image;

Does this help?

Best regards,

  • You must to post comments

This didn’t help.

I’m wondering if you are doing something, like drawing on a display link callback, that is not triggering if the chart is not added to an on screen view. Is this possible?

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.