2012-02-15 19 views
4

現在、私はiPhoneとiPad用のペイントアプリケーションに取り組んでいます。私は画面の現在の画面表示(描画)を印刷したい。これらの事件で、どんな体が私を助けることができますか?ここで iOs現在の画面を印刷

は、代わりに画像ユチョンの繰り返しに

-(void)printImage { 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"micky" ofType:@"png"]; 
    NSData *dataFromPath = [NSData dataWithContentsOfFile:path]; 

    UIPrintInteractionController *pCon = [UIPrintInteractionController sharedPrintController]; 

    if(pCon && [UIPrintInteractionController canPrintData:dataFromPath]) { 
     pCon.delegate = self; 
     UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
     printInfo.outputType = UIPrintInfoOutputGeneral; 
     printInfo.jobName = [path lastPathComponent]; 
     printInfo.duplex = UIPrintInfoDuplexLongEdge; 
     pCon.printInfo = printInfo; 
     pCon.showsPageRange = YES; 
     pCon.printingItem = dataFromPath; 

     void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { 
      if (!completed && error) { 
       NSLog(@"Unsuccessfull %@ error%u", error.domain, error.code); 
      } 
     }; 

     [pCon presentAnimated:YES completionHandler:completionHandler]; 

    } 
} 

、私は現在のウィンドウを印刷することができるはずである知りたいすべてが(描画、スクリーン)私は、これまで使用してきたコードです。

答えて

3

(コードのように)PNGこのコードは、現在のビューのスクリーンショットを取り、それのUIImageを出力:

+0

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [self.view.layer renderInContext:context]; UIImage *imageFromCurrentView = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 
ありがとうのthatsのが魅力のように働きます。私はもう少しこれを強化したいと思います。私が現在の画面で特定のビューのスクリーンショットを取得したい場合は、どうしたらいいですか? – BigAppleBump

+0

は、 'self.view'の出現箇所を取得するビューに置き換えます。この回答に合格とマークしてください:) – samvermette

+0

はい。どうもありがとうございました – BigAppleBump

関連する問題