小编typ*_*ter的帖子

大型UIImage绘制后,CGContextDrawImage非常慢

CGContextDrawImage(CGContextRef,CGRect,CGImageRef)在绘制由CoreGraphics(即使用CGBitmapContextCreateImage)创建的CGImage时,执行MUCH WORSE比绘制支持UIImage的CGImage时要好.看到这个测试方法:

-(void)showStrangePerformanceOfCGContextDrawImage
{
    ///Setup : Load an image and start a context:
    UIImage *theImage = [UIImage imageNamed:@"reallyBigImage.png"];
    UIGraphicsBeginImageContext(theImage.size);
    CGContextRef ctxt = UIGraphicsGetCurrentContext();    
    CGRect imgRec = CGRectMake(0, 0, theImage.size.width, theImage.size.height);


    ///Why is this SO MUCH faster...
    NSDate * startingTimeForUIImageDrawing = [NSDate date];
    CGContextDrawImage(ctxt, imgRec, theImage.CGImage);  //Draw existing image into context Using the UIImage backing    
    NSLog(@"Time was %f", [[NSDate date] timeIntervalSinceDate:startingTimeForUIImageDrawing]);

    /// Create a new image from the context to use this time in CGContextDrawImage:
    CGImageRef theImageConverted = CGBitmapContextCreateImage(ctxt);

    ///This is …
Run Code Online (Sandbox Code Playgroud)

performance core-graphics ios cgcontextdrawimage

28
推荐指数
2
解决办法
1万
查看次数