以下是如何在上下文中绘制UIImage:
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
[someUIImage drawInRect:CGRectMake(...)];
[someOtherUIImage drawInRect:CGRectMake(...)];
[someOtherUIImage drawInRect:CGRectMake(...)];
UIImage *yourResult = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
没问题。但是,假设我有一个以某种方式构建的CGImageRef。
CGImageRef happyImageRef = CGImageCreateWithImageInRect(blah blah);
我想将它绘制到上下文中。
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
[ happyImageRef .. somehowDrawInRect:CGRectMake(...)];
UIImage *yourResult = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
你是怎么做到的?
要清楚,显然你可以将其转换为UIImage
UIImage *wasteful = [UIImage imageWithCGImage:happyImageRef];
但这似乎非常低效。怎么做?
我确信我很困惑或遗漏了一些简单的东西,谢谢。
答案 0 :(得分:5)
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0f);
CGContextDrawImage(UIGraphicsGetCurrentContext(),CGRectMake(...), happyImageRef);
UIImage *yourResult = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();