ios - Objective-C, How to rotate images and stretch for PDF printing -
i trying app prints 4 photos onto pdf. these photos size , orientation.
i trying these photos printed specific places in pdf. if image portrait want printed, if landscape want rotate before print it. want photo fill entire of space.
i have been trying while , closet have got.
as can see bottom 2 photos (landscape have been rotated) narrower portrait ones @ top. can see issues code below. apologise, attempt after attempt might not 100% clear.
acutal calls
[pdfcreator drawphoto:image1 : cgrectmake(60, 60, 226, 340)]; [pdfcreator drawphoto:image2 : cgrectmake(326, 60, 226, 340)]; [pdfcreator drawphoto:image3 : cgrectmake(60, 407, 226, 340)]; [pdfcreator drawphoto:image4 : cgrectmake(326, 407, 226, 340)];
code
+ (void) drawphoto : (uiimage*) photo : (cgrect) location{ [[pdfcreator imagewithimage:[pdfcreator scaleandrotateimage:photo] scaledtosize:cgsizemake(location.size.width, location.size.height) ] drawinrect:location]; } + (uiimage*) scaleandrotateimage: (uiimage*) imagein { if(imagein.size.width > imagein.size.height) { cgfloat rads = m_pi * 90 / 180; float newside = max([imagein size].width, [imagein size].height); cgsize size = cgsizemake(newside, newside); uigraphicsbeginimagecontext(size); cgcontextref ctx = uigraphicsgetcurrentcontext(); cgcontexttranslatectm(ctx, newside/2, newside/2); cgcontextrotatectm(ctx, rads); cgcontextdrawimage(uigraphicsgetcurrentcontext(),cgrectmake(-[imagein size].width/2,-[imagein size].height/2,size.width, size.height),imagein.cgimage); imagein = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); } return imagein; } + (uiimage*)imagewithimage:(uiimage*)image scaledtosize:(cgsize)newsize { uigraphicsbeginimagecontext( newsize ); [image drawinrect:cgrectmake(0,0,newsize.width,newsize.height)]; uiimage* newimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return newimage; }
thanks
Comments
Post a Comment