iphone - How to print photo in iOS? -
i need print photo using airprinter , coded have 1 problem photo size. after print photo, can see output photo size large - correctly want print a6(4*6 inch) photo.
i use canon mg3260 air printer.
please me if can solve problem.
- screenshot https://www.dropbox.com/s/1f6wa0waao56zqk/img_0532.jpg
code
-(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]; }
scale image first , use print
+ (uiimage *)imagewithimage:(uiimage *)image scaledtosize:(cgsize)newsize { //uigraphicsbeginimagecontext(newsize); uigraphicsbeginimagecontextwithoptions(newsize, no, 0.0); [image drawinrect:cgrectmake(0, 0, newsize.width, newsize.height)]; uiimage *newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return newimage; }
Comments
Post a Comment