0

В моем приложении у меня есть возможность сделать купон, просмотреть его, и у них есть возможность распечатать этот купон. Прямо сейчас он просто разрастается по экрану, чтобы включать только купонную часть и печатает, но он печатает до полноразмерного 8.5 x 11 и использует много чернил, делая этот купон черным в фоновом режиме. Как это может быть изменено только печать сказать раздел 2.5 х 3.5 "бумаги?Изменить размер изображения в iOS

-(void)printer { 

    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; 

    if(!controller){ 

     NSLog(@"Couldn't get shared UIPrintInteractionController!"); 

     return; 

    } 

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = 

    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { 

     if(!completed && error){ 

      NSLog(@"FAILED! due to error in domain %@ with error code %u", 

        error.domain, error.code); 

     } 

    }; 
    CGRect rect; 
    rect=CGRectMake(0, 0, 320, 480); 
    UIGraphicsBeginImageContext(rect.size); 

    CGContextRef context=UIGraphicsGetCurrentContext(); 
    [self.tabBarController.view.layer renderInContext:context]; 

    UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    UIImage *img = [self cropImage:image rect:CGRectMake(20,70,279,359)]; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 

    printInfo.outputType = UIPrintInfoOutputPhoto; 

    printInfo.jobName = @"Your Coupon"; 

    controller.printInfo = printInfo; 

    controller.showsPageRange = YES; 



    controller.printingItem = img; 



    [controller presentAnimated:YES completionHandler:completionHandler]; 


} 

ответ

1

Похоже, он масштабирует изображение при печати до полного размера выходных СМИ. Вы можете попробовать положить купон изображение на большее изображение и печать этого составного изображения. Я не тестировал этот код, но это адаптация того, что я делаю для обрезки изображений.

UIImage *img = [self cropImage:image rect:CGRectMake(20,70,279,359)]; 
// Some size for the full image. 
// Obviously you need to experiment with this to get the size right 
CGSize targetSize = CGSizeMake(800, 1050); 

// This will put the image in the upper left corner 
// you could put it in the middle or wherever 
CGPoint imageOrigin = CGPointMake(0, 0); 
CGRect imageRect = CGRectMake(imageOrigin.x, imageOrigin.y, img.size.width, img.size.height); 

// Always scale to the screen scale to get the sharpest images even at the expense of size. 
UIGraphicsBeginImageContextWithOptions(targetSize, NO, 0); 
[img drawInRect:imageRect]; 
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

// print configuration stuff from your code example goes here... 

controller.printingItem = newImage; 
Смежные вопросы