ios - Cropping an UIImage -
i've got code resizes image can scaled chunk of center of image - use take uiimage
, return small, square representation of image, similar what's seen in album view of photos app. (i know use uiimageview
, adjust crop mode achieve same results, these images displayed in uiwebviews
).
i've started notice crashes in code , i'm bit stumped. i've got 2 different theories , i'm wondering if either on-base.
theory 1) achieve cropping drawing offscreen image context of target size. since want center portion of image, set cgrect
argument passed drawinrect
that's larger bounds of image context. hoping kosher, instead attempting draw on other memory shouldn't touching?
theory 2) i'm doing of in background thread. know there portions of uikit restricted main thread. assuming / hoping drawing offscreen view wasn't 1 of these. wrong?
(oh, how miss nsimage's drawinrect:fromrect:operation:fraction:
method.)
update 2014-05-28: wrote when ios 3 or hot new thing, i'm there better ways now, possibly built-in. many people have mentioned, method doesn't take rotation account; read additional answers , spread upvote love around keep responses question helpful everyone.
original response:
i'm going copy/paste response same question elsewhere:
there isn't simple class method this, there function can use desired results: cgimagecreatewithimageinrect(cgimageref, cgrect)
out.
here's short example using it:
cgimageref imageref = cgimagecreatewithimageinrect([largeimage cgimage], croprect); // or use uiimage wherever [uiimageview setimage:[uiimage imagewithcgimage:imageref]]; cgimagerelease(imageref);
Comments
Post a Comment