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