IO Print Current Screen

I am currently working on a Paint Application for iPhones and iPads. I want to print the current screen (Drawing) screen. Can someone help me in this case?

Here is the code I've used so far,

-(void)printImage { NSString *path = [[NSBundle mainBundle] pathForResource:@"micky" ofType:@"png"]; NSData *dataFromPath = [NSData dataWithContentsOfFile:path]; UIPrintInteractionController *pCon = [UIPrintInteractionController sharedPrintController]; if(pCon && [UIPrintInteractionController canPrintData:dataFromPath]) { pCon.delegate = self; UIPrintInfo *printInfo = [UIPrintInfo printInfo]; printInfo.outputType = UIPrintInfoOutputGeneral; printInfo.jobName = [path lastPathComponent]; printInfo.duplex = UIPrintInfoDuplexLongEdge; pCon.printInfo = printInfo; pCon.showsPageRange = YES; pCon.printingItem = dataFromPath; void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { if (!completed && error) { NSLog(@"Unsuccessfull %@ error%u", error.domain, error.code); } }; [pCon presentAnimated:YES completionHandler:completionHandler]; } } 

Again, all I want to know is that I should be able to print the current window (image, screen) instead of the Micky.png image (as in the code)

+4
source share
1 answer

This code displays a screenshot of the current view and infers UIImage from this:

 UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 
+3
source

Source: https://habr.com/ru/post/1396691/


All Articles