ios - UIImageView: get transformed UIImage -


i'm rotating uiimageview using this:

[uiview beginanimations:nil context:nil]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationcurve:uiviewanimationcurveeasein]; myimgview.transform = cgaffinetransformmakerotation(angle*m_pi/180); [uiview commitanimations]; 

now want rotated image. can this? trying make coregraphics using cgimagerotatedbyangle function accepted answer this question transforms coordinates slighlty incorrect (finally third screenshot marked wrong). can see image loses original size , cropped. goal image on central shot original size , rotated specified angle. mean it's required size of rotated shape stay unchanged new image of course gonna larger initial.

enter image description here

ok, i'm answering own question again, useful in future... coming cgimagerotatedbyangle said gives required effect coordinate system translation sequence must slighly altered. , here way got desired result:

- (cgimageref)cgimagerotatedbyangle:(cgimageref)imgref angle:(cgfloat)angle {      cgfloat angleinradians = angle * (m_pi / 180);     cgfloat width = cgimagegetwidth(imgref);     cgfloat height = cgimagegetheight(imgref);      cgrect imgrect = cgrectmake(0, 0, width, height);     cgaffinetransform transform = cgaffinetransformmakerotation(angleinradians);     cgrect rotatedrect = cgrectapplyaffinetransform(imgrect, transform);     cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();      cgcontextref bmcontext = cgbitmapcontextcreate(null,                                                    rotatedrect.size.width,                                                    rotatedrect.size.height,                                                    8,                                                    0,                                                    colorspace,                                                    kcgimagealphapremultipliedfirst);     cgcontextsetallowsantialiasing(bmcontext, yes);     cgcontextsetshouldantialias(bmcontext, yes);     cgcontextsetinterpolationquality(bmcontext, kcginterpolationhigh);     cgcolorspacerelease(colorspace);     cgcontexttranslatectm( bmcontext, 0.5f * rotatedrect.size.width, 0.5f * rotatedrect.size.height ) ;     cgcontextrotatectm(bmcontext, angleinradians);     cgcontextdrawimage(bmcontext, cgrectmake(-imgrect.size.width* 0.5f, -imgrect.size.height * 0.5f,                                              imgrect.size.width,                                              imgrect.size.height),                        imgref);     cgimageref rotatedimage = cgbitmapcontextcreateimage(bmcontext);     cfrelease(bmcontext);     [(id)rotatedimage autorelease];      return rotatedimage; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -