2013-05-15 91 views
0

我需要使用AirPrinter打印照片並已經編碼,但是我的照片尺寸有一個問題。 打印完照片後,我可以看到輸出照片尺寸太大 - 正確地打印A6(4 * 6英寸)照片。如何在iOS中打印照片?

我使用佳能MG3260作爲空氣打印機。

請幫我,如果我能解決這個問題。

  • 截圖 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]; 
    
    } 
    

回答

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

我已經使用縮放圖像! – Zhenxin