Fork me on GitHub

iphone中的双缓冲

-(void)drawRect:(CGRect)rect {

NSString* imageName = [[NSString alloc]initWithFormat:@”b%d.png”,m_Index];

UIImage* aImage = [UIImage imageNamed:imageName];

[imageName release];

int width = aImage.size.width;

int height = aImage.size.height;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef context = CGBitmapContextCreate(nil,width,height,8,0, colorSpace,kCGImageAlphaPremultipliedLast);

CFRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width,height), aImage.CGImage);

CGImageRef image = CGBitmapContextCreateImage(context);

CGContextRelease(context);

UIImage* display = [UIImage imageWithCGImage:image];

[display drawInRect:CGRectMake((480-width)/2, (320-height)/2,width,height)];

}

 

posted on 2012-05-15 20:19  pengyingh  阅读(282)  评论(0)    收藏  举报

导航