UIImage,CGImage和CGImageRef 区别

CGImage和CGImageRef这两个应当是用来重绘图形的类,它们在应用时是按照图像的像素矩阵来绘制图片的,它们可以用来处理bitmap。
CGImageRef与UIImage的互转

  1. CGImageRef转换成UIImage
    CGImageRef iOffscreen = CGBitmapContextCreateImage(context);
    UIImage* image = [UIImage imageWithCGImage: iOffscreen];

2.UIImage转换成CGImageRef
UIImage *loadImage=[UIImage imageNamed:@”comicsplash.png”];
CGImageRef cgimage=loadImage.CGImage;

UIView转UIImage(截屏,UIGraphicsBeginImageContextWithOptions函数的使用)

// 需要转成image的view:captureAndSaveView
UIGraphicsBeginImageContextWithOptions(captureAndSaveView.frame.size, NO, 1.0); //NO,YES 控制是否透明

[captureAndSaveView.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
// 生成后的image

哪位大侠解释下UIColor与CGColor,这俩有啥区别
CGColor就是UIColor的一个属性
有些设定颜色 要求的类型就是CGColor的所以用CGColor
如CGContextSetFillColorWithColor(g, [UIColor greyColor].CGColor);

另外下面一个CGColor的用法希望能帮到你
const CGFloat *components = CGColorGetComponents(color.CGColor);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值