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?
- Brian Smith asked 6 years ago
- You must login to post comments
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.
- Andrew Burnett-Thompson answered 3 years ago
- You must login 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();
UIGraphicsEndImageContext();
return image;
}
Does this help?
Best regards,
Andrew
- Andrew Burnett-Thompson answered 6 years ago
- last edited 2 years ago
- You must login 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?
- Brian Smith answered 6 years ago
-
Hello Brian, You are right, it’s drawing on a display link callback, and you are right, it’s need to be added into view on screen. Also, you might want to use exportToUIImage: method from SCIChartSurfaceProtocol – https://www.scichart.com/documentation/ios/current/Protocols/ISCIChartSurfaceBase.html#/c:objc(pl)ISCIChartSurfaceBase(im)exportToUIImage, which is doing the code Andrew provided above. Best Regards, Nazar R.
- You must login to post comments
Please login first to submit.