Iphone 如何在iOS中打印照片?

Iphone 如何在iOS中打印照片?,iphone,ios,airprint,Iphone,Ios,Airprint,我需要打印照片使用AirPrinter和已经编码,但我有一个与照片大小的问题。 打印照片后,我可以看到输出照片尺寸太大-正确地说,我想打印一张6英寸(4*6英寸)的照片 我使用佳能MG3260作为空气打印机 如果我能解决这个问题,请帮助我 截图 代码 -(void)printPhotoWithImage:(UIImage *)image { NSData *myData = UIImageJPEGRepresentation(image, 1.f); UIPrintInteractionC

我需要打印照片使用AirPrinter和已经编码,但我有一个与照片大小的问题。 打印照片后,我可以看到输出照片尺寸太大-正确地说,我想打印一张6英寸(4*6英寸)的照片

我使用佳能MG3260作为空气打印机

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

  • 截图
  • 代码

    -(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];
    
    }


首先缩放图像,然后使用它进行打印

+ (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;
}
+ (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;
}