0

我需要使用 AirPrinter 打印照片并且已经编码,但是照片尺寸有一个问题。打印照片后,我可以看到输出照片尺寸太大 - 正确我想打印 A6(4*6 英寸)照片。

我使用佳能 MG3260 作为 Air Printer。

如果我能解决这个问题,请帮助我。

  • 截图 https://www.dropbox.com/s/1f6wa0waao56zqk/IMG_0532.jpg
  • 代码

    -(void)printPhotoWithImage:(UIImage *)image {
    
    NSData *myData = UIImageJPEGRepresentation(image, 1.f); UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    
    if (pic && [UIPrintInteractionController canPrintData:myData]) {
    
    pic.delegate = self;
    UIPrintInfo *pinfo = [UIPrintInfo printInfo];
    pinfo.outputType = UIPrintInfoOutputPhoto;
    pinfo.jobName = @"My Photo";
    pinfo.duplex = UIPrintInfoDuplexLongEdge;
    
    pic.printInfo = pinfo;
    pic.showsPageRange = YES;
    pic.printingItem = myData;
    
    pic.printFormatter = format;
    [format release];
    
    void(^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *print, BOOL completed, NSError *error) {
    
    [self resignFirstResponder];
    
    if (!completed && error) {
        NSLog(@"--- print error! ---");
    }
    
    };
    
       [pic presentFromRect:CGRectMake((self.view.bounds.size.width - 64) + 27, (self.view.bounds.size.height - 16) + 55, 0, 0) inView:self.view animated:YES completionHandler:completionHandler];
    

    }

     - (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray *)paperList {
    
     CGSize pageSize = CGSizeMake(6 * 72, 4 * 72); return [UIPrintPaper bestPaperForPageSize:pageSize withPapersFromArray:paperList];
    
    }
    
4

1 回答 1

0

先缩放图像,然后用它来打印

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}
于 2013-05-15T08:55:21.930 回答