creates a subimage and draws it enlarged
myImageArea = CGRectMake (rooster_head_x_origin, rooster_head_y_origin, |
myWidth, myHeight); |
mySubimage = CGImageCreateWithImageInRect (myRoosterImage, myImageArea); |
myRect = CGRectMake(0, 0, myWidth*2, myHeight*2); |
CGContextDrawImage(context, myRect, mySubimage); |
Mask image
+ (UIImage*) maskImage:(UIImage*)image withMask:(UIImage*)mask {
CGImageRef imgRef = [image CGImage];CGImageRef maskRef = [mask CGImage];
CGImageRef actualMask =CGImageMaskCreate(CGImageGetWidth(maskRef),CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef),
NULL,false);
CGImageRef masked = CGImageCreateWithMask(imgRef,actualMask);
return [UIImageimageWithCGImage:masked];
}
// 颜色mask
const CGFloat myMaskingColors[6] = {124,255, 68, 222,0, 165};
CGImageRef newImage = CGImageCreateWithMaskingColors(image.CGImage, myMaskingColors);
// 将屏幕的内容翻转
// CGContextTranslateCTM(context,self.bounds.size.width, self.bounds.size.height);
// CGContextRotateCTM(context,M_PI);
CGContextTranslateCTM(context,0, self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
本文介绍如何使用Core Graphics API创建子图像,并将其放大两倍进行绘制。此外,还介绍了如何利用CGImage创建带遮罩的图像以及如何通过颜色遮罩来修改图像。最后,文章展示了如何设置上下文以翻转屏幕内容。

被折叠的 条评论
为什么被折叠?



