iphone - iOs 打印我的当前屏幕

标签 iphone ios

目前我正在为 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/

相关文章:

ios - marker.iconView?.addSubview(UIButton) 无法使用 Gmaps 点击

iphone - 在 iOS 上点击文本区域时 CKEditor 不聚焦

ios - 如何使用 DNS 域连接到 SIP 服务器

iphone - UITableView CoreData 断言失败

iPhone SDK :Is it possible to use an UISwitch to enable and disable PNS(Push Notification Service)?

ios - 检测 CAShapeLayer 列表中的长按

ios - skscene 中的 skscene

ios - 获取 SCNSphere 上的点击位置 - Swift (SceneKit)/iOS

ios - iPad布局问题

iphone - UISearchBar 在 UITableView 滚动时滚动