ios - Resize UIImage is inverting the orientation -
i'm trying resize uiimage when this, uiimage changing orientation. original image in vertical when resize image's orientation horizontal
- (uiimage *)resizeimage:(uiimage*)image newsize:(cgsize)newsize { cgrect newrect = cgrectintegral(cgrectmake(0, 0, newsize.width, newsize.height)); cgimageref imageref = image.cgimage; uigraphicsbeginimagecontextwithoptions(newsize, no, 0); cgcontextref context = uigraphicsgetcurrentcontext(); // set quality level use when rescaling cgcontextsetinterpolationquality(context, kcginterpolationhigh); cgaffinetransform flipvertical = cgaffinetransformmake(1, 0, 0, -1, 0, newsize.height); cgcontextconcatctm(context, flipvertical); // draw context; scales image cgcontextdrawimage(context, newrect, imageref); // resized image context , uiimage cgimageref newimageref = cgbitmapcontextcreateimage(context); uiimage *newimage = [uiimage imagewithcgimage:newimageref]; cgimagerelease(newimageref); uigraphicsendimagecontext(); return newimage; }
i think problem having related use of cgaffinetransformmake
. try following code:
- (uiimage *)resizeimage:(uiimage*)image newsize:(cgsize)newsize { uigraphicsbeginimagecontextwithoptions(newsize, no, 0.f); [image drawinrect:cgrectmake(0, 0, newsize.width, newsize.height)]; uiimage *resizedimage = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return resizedimage; }
Comments
Post a Comment