【问题标题】:How to print an image to its exact size in iOS application?如何在 iOS 应用程序中将图像打印到其确切尺寸?
【发布时间】:2014-07-11 07:41:09
【问题描述】:

我在我的应用程序中打印不同的图像。问题是打印机总是在整个页面中打印图像。如果图像尺寸非常小,打印机会在整个页面上打印,并且看起来很糟糕。我正在使用以下代码打印图像:-

        NSData *dataFromPath = UIImageJPEGRepresentation(croppedImage, 1.0);
    if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {

        printController.delegate = self;
        UIPrintFormatter *my=[[UIPrintFormatter alloc]init];
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = @"print image";
        printInfo.duplex = UIPrintInfoDuplexNone;
        printController.printInfo = printInfo;
        printController.showsPageRange = YES;
        printController.printingItem = dataFromPath;
        [printController presentFromRect:_btn_ShareAction.frame inView:_btn_ShareAction.superview animated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
            if (!completed && error) {
                NSLog(@"FAILED! due to error in domain %@ with error code %ld", error.domain, (long)error.code);
            }
        }];

    }

【问题讨论】:

  • 所以我想要一个总是根据图像大小打印图像而不总是占据整个页面的解决方案。
  • 我尝试缩小图像以便正确打印但仍然存在同样的问题,有人知道这个问题吗?

标签: ios objective-c ipad ipad-2 uiprintinteractioncntrler


【解决方案1】:

您可以使用printPageRenderer 属性来代替printingItem 并实现您自己的打印逻辑,这将使您能够根据需要在确切的位置和大小进行打印。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-04
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多