2

我正在尝试通过 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 的 PrintPhoto代码。

任何提示或想法将不胜感激!

4

0 回答 0