Clipping different parts of an image with path
Posted
by huggie
on Stack Overflow
See other posts from Stack Overflow
or by huggie
Published on 2010-04-18T06:46:02Z
Indexed on
2010/04/18
6:53 UTC
Read the original article
Hit count: 562
I've recently asked a question about clipping an image via path at view's drawRect method.
http://stackoverflow.com/questions/2570653/iphone-clip-image-with-path
Krasnyk's code is copied below.
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
//or for e.g. CGPathAddRect(path, NULL, CGRectInset([self bounds], 10, 20));
CGPathAddEllipseInRect(path, NULL, [self bounds]);
CGContextAddPath(context, path);
CGContextClip(context);
CGPathRelease(path);
[[UIImage imageNamed:@"GC.png"] drawInRect:[self bounds]];
}
It works very well. However, when my image is larger than the view itself, how do I show different parts of the image?
I tried tweaking around with translation on the locations (show as bounds above) of ellipse and/or UIImage drawInRect but some complex effects (Unwanted clipping, weird elipse size) I can't explain happens.
© Stack Overflow or respective owner