how to drawImage in context with scale and mask?
I'm making a magnifier view with scale and render a part of view in a
magnifier-shape mask, like following
- (UIImage *)magnifierInFrame:(CGRect)frame scale:(CGFloat)scaleFactor {
CGSize imageSize = frame.size;
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextScaleCTM(c, scaleFactor, scaleFactor);
CGContextConcatCTM(c,
CGAffineTransformMakeTranslation(-frame.origin.x,
-frame.origin.y));
[[UIImage imageNamed:@"magnifier_background"] drawInRect:frame];
CGContextClipToMask(c, frame, [UIImage
imageNamed:@"magnifier_content_mask"].CGImage);
[self.layer renderInContext:c];
UIImage *magnifierImage =
UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return magnifierImage;
}
because I scale the context, as a result, the magnifier_content_mask area
is scaled as well, but it should not scale magnifier_content_mask and
magnifier_background area, and only scale view content in frame, is there
any way to do it?
No comments:
Post a Comment