UIPrintInteractionController使用要打印的数据。如果我想从imageview打印图像,它会给我一些警告。我想使用来自imageview的图像而不是来自资源。我想知道如何从ImageView中的图像中获取数据
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
NSData * datatobeprinted [NSData dataWithContentsOfFile:imageView.image];
if(printController && [UIPrintInteractionController canPrintData:imageView.image]) {
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [path lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
[printController setPrintingItem:datatobeprinted];
}
答案 0 :(得分:1)
我认为您需要来自图像的NSData,然后您可以执行以下操作:
NSData *imageData = UIImageJPEGRepresentation(image, 0.7); // 0.7 is JPG quality
或
NSData *imageData = UIImagePNGRepresentation(image);
取决于您希望数据采用PNG格式还是JPG格式。