background image

         CGContextSetRGBStrokeColor(iDevice, 1.0, 0.0, 0.0, 1.0);
         CGPoint pt0, pt1;
         CGPoint points[2];
        
         pt0.x = 10;
         pt0.y = 250;
        
         pt1.x = 310;
         pt1.y = 250;
        
         points[0] = pt0;
         points[1] = pt1;
        
         CGContextAddLines(iDevice, points, 2);
         CGContextStrokePath(iDevice);

    可见,在被渲染的内存区域的“位图上下文”中可以进行图片、矩形、直线等各种绘制操作,
这些操作被渲染成位图数据,读者可以通过如下方法获取到这个被渲染的

“位图”:

-(void)drawRect:(CGRect)rect {
    // Drawing code
         UIGraphicsGetCurrentContext();
        
         UIImage* iImage = [UIImage imageNamed:@"merry.png"];
         [iOffScreenBitmap DrawImage:iImage.CGImage];
         UIImage* iImage_1 = [UIImage imageWithCGImage:[iOffScreenBitmap Gc]];

         [iImage_1 drawInRect:CGRectMake(0, 0, 120, 160)];
}

    上面的代码中,通过 iOffScreenBitmap 的 DrawImage:CGImageRef 方法把图片 merry.png
绘 制 到 屏 幕 双 缓 冲 中 , 并 接 着 进 行 了 矩 形 、 直 线 绘 制 , 然 后 通 过
CGBitmapContextCreateImage:CGConotextRef 方 法 获 取 “ 视 图 上 下 文 ” 的 “ 视 图 快 照

snapshot)”image_1,最后把这个“视图快照”更新到屏幕上,从而实现屏幕双缓冲的技术。