簡體   English   中英

如何在iOS應用程序中將圖像打印到其確切尺寸?

[英]How to print an image to its exact size in iOS application?

我正在應用程序中打印不同的圖像。 問題是打印機始終在整個頁面上打印圖像。 如果圖像尺寸很小,則打印機將在整個頁面上打印,並且看起來非常糟糕。 我正在使用以下代碼來打印圖像:

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

    }

而不是使用的printingItem可以使用printPageRenderer財產和實現自己的打印邏輯,這將使你的確切位置和大小,要打印。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM