目前我正在为 iPhone 和 iPad 开发一个画图应用程序。我想打印屏幕的当前屏幕显示(绘图)。在这种情况下,任何人都可以帮助我吗?
这是我到目前为止使用的代码,
-(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];
}
}
同样,我想知道的是我应该能够打印当前窗口(绘图、屏幕)而不是图像 Micky.png(如代码中所示)
最佳答案
此代码获取当前 View 的屏幕截图并输出它的 UIImage
:
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
关于iphone - iOs 打印我的当前屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9299208/