您的位置:首页 > 产品设计 > UI/UE

UIImage,CGImage和CGImageRef 区别

2016-03-31 09:55 489 查看
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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: