Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用UIPrintInteractionController的照片大小_Iphone - Fatal编程技术网

Iphone 使用UIPrintInteractionController的照片大小

Iphone 使用UIPrintInteractionController的照片大小,iphone,Iphone,我有一个问题,打印照片使用AirPrint。我打印了4*6英寸的图像,但是打印的图像太大了!如何解决此问题。 我可以通过编程方式指定图纸尺寸和照片吗 这里是屏幕截图url `这是我的密码 -(void)printPhotoWithImage:(UIImage *)image { NSData *myData = UIImageJPEGRepresentation(image, 1.f); UIPrintInteractionController *pic = [UIPrint

我有一个问题,打印照片使用AirPrint。我打印了4*6英寸的图像,但是打印的图像太大了!如何解决此问题。
我可以通过编程方式指定图纸尺寸和照片吗

这里是屏幕截图url

`这是我的密码

-(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];
}
这是我的密码。我应该使用
UIPrintPageRenderer
属性来指定绘图区域吗

`首先,您应该设置

 /*
 PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init];
    pageRenderer.imageToPrint =image;
    pic.printPageRenderer = pageRenderer;
*/
 - (void)printImage {
// Obtain the shared UIPrintInteractionController
UIPrintInteractionController *controller = [UIPrintInteractionController     sharedPrintController];
controller.delegate = self;
if(!controller){
    NSLog(@"Couldn't get shared UIPrintInteractionController!");
    return;
}

// We need a completion handler block for printing.
UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController     *printController, BOOL completed, NSError *error) {
    if(completed && error)
        NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain,     error.code);
};

// Obtain a printInfo so that we can set our printing defaults.
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
UIImage *image = ((UIImageView *)self.view).image;
[controller setDelegate:self];


printInfo.outputType = UIPrintInfoOutputPhoto;

if(!controller.printingItem && image.size.width > image.size.height)
    printInfo.orientation = UIPrintInfoOrientationLandscape;

// Use this printInfo for this print job.
controller.printInfo = printInfo;

//  Since the code below relies on printingItem being zero if it hasn't
//  already been set, this code sets it to nil.
controller.printingItem = nil;


#if DIRECT_SUBMISSION
// Use the URL of the image asset.
if(self.imageURL && [UIPrintInteractionController canPrintURL:self.imageURL])
    controller.printingItem = self.imageURL;
#endif

// If we aren't doing direct submission of the image or for some reason we don't
// have an ALAsset or URL for our image, we'll draw it instead.
if(!controller.printingItem){
    // Create an instance of our PrintPhotoPageRenderer class for use as the
    // printPageRenderer for the print job.
    PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init];
    // The PrintPhotoPageRenderer subclass needs the image to draw. If we were taking
    // this path we use the original image and not the fullScreenImage we obtained from
    // the ALAssetRepresentation.
    //pageRenderer.imageToPrint = ((UIImageView *)self.view).image;
    pageRenderer.imageToPrint =image;
    controller.printPageRenderer = pageRenderer;
}

// The method we use presenting the printing UI depends on the type of
// UI idiom that is currently executing. Once we invoke one of these methods
// to present the printing UI, our application's direct involvement in printing
// is complete. Our delegate methods (if any) and page renderer methods (if any)
// are invoked by UIKit.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    //[controller presentFromBarButtonItem:self.printButton animated:YES     completionHandler:completionHandler];  // iPad
     [controller presentFromRect:CGRectMake(0, 0, 50, 50) inView:_btnPrint animated:YES     completionHandler:completionHandler];
}else
    [controller presentAnimated:YES completionHandler:completionHandler];  // iPhone

}
然后您应该设置PrintPhotoPageRenderer

UIPrintPageRenderer.h

    #import <UIKit/UIKit.h>


@interface PrintPhotoPageRenderer : UIPrintPageRenderer {   UIImage
*imageToPrint; }

@property (readwrite, retain) UIImage *imageToPrint;

@end

//

谢谢你的快速回复,但我是这个网站的新手,所以很遗憾我不能附加我的代码。我已经指定了纸张大小,并且应该如何限制照片大小?更新问题使用您想要的图像的高度和宽度,而不是英寸:(@user2374360-要发布您的代码,您可以在编辑问题时使用“代码片段”工具。该图标看起来像两个大括号({})。谢谢你告诉我。这样我就可以用{}显示我的代码了。:)嗨,lxt,我可以用其他工具上传照片吗?
 #import "PrintPhotoPageRenderer.h"

@implementation PrintPhotoPageRenderer

@synthesize imageToPrint;

// This code always draws one image at print time.
-(NSInteger)numberOfPages {   return 1; }

/*  When using this UIPrintPageRenderer subclass to draw a photo at
print
    time, the app explicitly draws all the content and need only override
    the drawPageAtIndex:inRect: to accomplish that.

    The following scaling algorithm is implemented here:
    1) On borderless paper, users expect to see their content scaled so that there is             no whitespace at the edge of the paper. So this
code scales the content to  fill the paper at the expense of
clipping any content that lies off the paper.
    2) On paper which is not borderless, this code scales the content so that it fills    the paper. This reduces the size of the
photo but does not clip any content.
*/
- (void)drawPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)printableRect {

      if(self.imageToPrint){

      CGSize finialSize =  CGSizeMake(560, 431);//you should set width and height for you self

      int x  =  20;

      int y = (printableRect.size.height - finialSize.height);

      CGRect finalRect = CGRectMake(x, y, finialSize.width, finialSize.height);

    [self.imageToPrint drawInRect:finalRect];

         }else {
    NSLog(@"%s No image to draw!", __func__);   } }

@end