0
在我的應用程序中,我有用戶製作優惠券,預覽它,並且他們可以選擇打印該優惠券。現在它只是裁剪屏幕以僅包含優惠券部分並進行打印,但它正在打印爲全尺寸8.5 x 11,並且使用大量墨水,因爲優惠券在背景中爲黑色。這怎麼可能改變只打印要說到紙張的2.5×3.5「節?更改iOS中圖像的打印尺寸
-(void)printer {
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if(!controller){
NSLog(@"Couldn't get shared UIPrintInteractionController!");
return;
}
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(!completed && error){
NSLog(@"FAILED! due to error in domain %@ with error code %u",
error.domain, error.code);
}
};
CGRect rect;
rect=CGRectMake(0, 0, 320, 480);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context=UIGraphicsGetCurrentContext();
[self.tabBarController.view.layer renderInContext:context];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *img = [self cropImage:image rect:CGRectMake(20,70,279,359)];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = @"Your Coupon";
controller.printInfo = printInfo;
controller.showsPageRange = YES;
controller.printingItem = img;
[controller presentAnimated:YES completionHandler:completionHandler];
}