开发者

How could I get CGContextRef from UIImage?

开发者 https://www.devze.com 2023-01-31 00:48 出处:网络
CGContextRef context = ??; // get fr开发者_如何学编程om UIImage *oldImage CGContextSaveGState(context);
    CGContextRef context = ??; // get fr开发者_如何学编程om UIImage *oldImage

    CGContextSaveGState(context);   
    CGRect drawRect = CGRectMake(0, 0, 320, 480);
    CGContextConcatCTM(context, transform);
    UIImage *newImage = [[UIImage alloc] init];
    CGContextDrawImage(context, drawRect, newImage.CGImage);
    [newImage drawInRect:CGRectMake(0, 0, 320, 480)];

    CGContextRestoreGState(context);

In short, what I want to do is [ UIImage -> make some transform -> transformed UIImage].

Any ideas? Big thanks!!


I think what you need is this:

UIGraphicsBeginImageContextWithOptions(newImageSize, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing commands go here
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Note that UIGraphicsGetImageFromCurrentImageContext() returns an autoreleased UIImage instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消