使用UIPrintInteractionController从URL打印照片剪辑我照片的部分内容

时间:2014-05-29 17:49:41

标签: ios airprint uiprintinteractioncntrler

我正在尝试通过UIPrintInteractionController打印照片。它应该以4x6的形式打印,但它确实如此,但它会剪切部分照片(不是全部,而是两个方向的半英寸)。我直接从URL打印,图像的最终像素大小为600 x 900像素。

Apple是否具有特定的像素大小,它可以将图像完美打印为4x6?有谁知道吗?我做错了吗?

代码:

NSURL *imageURL = [NSURL URLWithString:urlOfImage];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *imageToPrint = [[UIImage alloc] initWithData:data];

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];

if(!controller){
    NSLog(@"Couldn't get shared UIPrintInteractionController!");
    return;
}

    controller.delegate = self;

// We need a completion handler block for printing.
UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
    if(completed && error)
        NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);

};

// Obtain a printInfo so that we can set our printing defaults.
UIPrintInfo *printInfo = [UIPrintInfo printInfo];

// This application prints photos. UIKit will pick a paper size and print
// quality appropriate for this content type.
printInfo.outputType = UIPrintInfoOutputPhoto;
// The path to the image may or may not be a good name for our print job
// but that's all we've got.
printInfo.jobName = [[imageURL path] lastPathComponent];

if(!controller.printingItem && imageToPrint.size.width > imageToPrint.size.height)
    printInfo.orientation = UIPrintInfoOrientationLandscape;

controller.printInfo = printInfo;

controller.printingItem = nil;

if(imageURL && [UIPrintInteractionController canPrintURL:imageURL])
    controller.printingItem = imageURL;

 if(!controller.printingItem)
 {
     PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init];
     // The PrintPhotoPageRenderer subclass needs the image to draw. If we were taking
     // this path we use the original image and not the fullScreenImage we obtained from
     // the ALAssetRepresentation.
     pageRenderer.imageToPrint = imageToPrint;
     controller.printPageRenderer = pageRenderer;
 }

[controller presentAnimated:YES completionHandler:completionHandler];

PrintPhotoRenderer直接来自Apple's PrintPhoto代码。

非常感谢任何提示或想法!

0 个答案:

没有答案