drawing - IOS: CGRect is right, but UIImage flipped -
i know have translate coordinate system, when drawing. thing when use:
cgcontexttranslatectm(_context, 0.0, _size.height); cgcontextscalectm(_context, 1.0, -1.0); my rect of image flipped, , image 'non-flipped', if dont use above image flipped, , rect non-flipped.
here's code:
cgrectmake(60, 100, image.size.width, image.size.height); cgcontextsavegstate(_context); uigraphicsbeginimagecontext(image.size); cgcontextclearrect(_context, placeholderrect); cgcontextdrawimage(_context, placeholderrect, image.cgimage); uigraphicsendimagecontext(); cgcontextrestoregstate(_context); how maintain rect (non-flipped), while image flipped?
thanks
the trick may lie in uiimage method
+ (uiimage *)imagewithcgimage:(cgimageref)imageref scale:(cgfloat)scale orientation:(uiimageorientation)orientation where orientation 1 of these :)
typedef enum { uiimageorientationup, uiimageorientationdown, // 180 deg rotation uiimageorientationleft, // 90 deg ccw uiimageorientationright, // 90 deg cw uiimageorientationupmirrored, // above image mirrored along other axis. horizontal flip uiimageorientationdownmirrored, // horizontal flip uiimageorientationleftmirrored, // vertical flip uiimageorientationrightmirrored, // vertical flip } uiimageorientation; edit: update
i did simple code sample in uiview subclass overriding drawrect , worked perfectly. doesn't use uiimage method works same.
uiimage *image = [uiimage imagenamed:@"image.png"]; cgcontextref _context = uigraphicsgetcurrentcontext(); cgcontextsavegstate(_context); cgcontextdrawimage(_context, cgrectmake(100, 20, image.size.width, image.size.height), image.cgimage); cgcontextscalectm(_context, -1.0f, 1.0f); cgcontextdrawimage(_context, cgrectmake(-300, 20, image.size.width, image.size.height), image.cgimage); cgcontextrestoregstate(_context);
Comments
Post a Comment