Image method

本文介绍如何使用Core Graphics API创建子图像,并将其放大两倍进行绘制。此外,还介绍了如何利用CGImage创建带遮罩的图像以及如何通过颜色遮罩来修改图像。最后,文章展示了如何设置上下文以翻转屏幕内容。

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,25568, 222,0, 165};

    CGImageRef newImage = CGImageCreateWithMaskingColors(image.CGImage, myMaskingColors);


// 将屏幕的内容翻转

  //  CGContextTranslateCTM(context,self.bounds.size.widthself.bounds.size.height);

   // CGContextRotateCTM(context,M_PI);

    CGContextTranslateCTM(context,0self.bounds.size.height);

    CGContextScaleCTM(context, 1.0, -1.0);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值