SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

0
0

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();
UIGraphicsEndImageContext();

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

Version
2.5.0.2533
  • You must to post comments
0
0

Hi Brian

We have a short code sample in our iOS Chart Documentation 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();
    UIGraphicsEndImageContext();
    return image;
}

Does this help?

Best regards,
Andrew

  • You must to post comments
0
0

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 2 results
Your Answer

Please first to submit.