gpt4 book ai didi

iphone - iOs 打印我的当前屏幕

转载 作者:可可西里 更新时间:2023-11-01 05:47:07 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com