以下是如何将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];
但这看起来极其低效。怎么做呢?
我肯定自己很困惑或者忽略了一些简单的东西,所以谢谢。