- (void)drawRect:(CGRect)rect {
// Drawing code.
stickerImage = [UIImage imageNamed:@"betaImage.png"];
CGSize size = stickerImage.size;
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM( con开发者_开发技巧text, 0.5f * size.width, 0.5f * size.height );
CGContextRotateCTM (context, 90 * M_PI/180);
[stickerImage drawInRect:(CGRect){ { -size.width * 0.5f, -size.height * 0.5f }, size }];
UIGraphicsEndImageContext();
}
I just cannot find whats wrong with my code, it does not showing anything
Don't begin and end an image context - that's for drawing to a UIImage. The current context has already been set to the view's context in drawRect - UIGraphicsGetCurrentContext() will give the right context out of the box.
In other words - get rid of UIGraphicsBeginImageContext() and UIGraphicsEndImageContext().
Yep, you shouldn't end your context before you get the result image. In your code example you should get the result image:
UIImage* yourImage = UIGraphicsGetImageFromCurrentImageContext();
or just pass ending context to other parent methods;
As Morgan Harris said, all image manipulations should be between UIGraphicsBeginImageContext() and UIGraphicsEndImageContext();
精彩评论