zoukankan      html  css  js  c++  java
  • iphone实现双缓冲

    原理不复杂:

    1. 创建一个bitmap context

    2. 在bitmap context上画东西

    3. 通过bitmap context生成一个CGImage

    4. 通过UIImage把CGImage内容画到屏幕上

    示例代码:

       // create the bitmap context
    
       CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    
       CGContextRef context = CGBitmapContextCreate(nil,27,27,8,0, colorSpace,kCGImageAlphaPremultipliedLast);
    
       CFRelease(colorSpace);
    
       // create an arrow image
    
       // set the fill color
    
       CGColorRef fillColor = [[UIColor blackColor] CGColor];
    
       CGContextSetFillColor(context, CGColorGetComponents(fillColor));
    
       CGContextBeginPath(context);
    
       CGContextMoveToPoint(context, 8.0f, 13.0f);
    
       CGContextAddLineToPoint(context, 24.0f, 4.0f);
    
       CGContextAddLineToPoint(context, 24.0f, 22.0f);
    
       CGContextClosePath(context);
    
       CGContextFillPath(context);
    
       // convert the context into a CGImageRef
    
       CGImageRef image = CGBitmapContextCreateImage(context);
    
       CGContextRelease(context);
    
       UIImage* image2 = [UIImage imageWithCGImage:image];
    
       [image2 drawInRect:CGRectMake(0, 0, 120, 160)];

    其中对context绘图的部分可以用来画耗时的3d动画等。

  • 相关阅读:
    leetcode—Swap Nodes in Pairs
    leetcode--Merge k Sorted Lists
    leetcode—Valid Parentheses
    leetcode—3sum
    编程工具(保持更新)
    QT下调用摄像头(opencv2.4.4)
    qtcreator 与 opencv
    在线公式编辑器
    QT学习(对话框)codeblock版本
    QT-opencv小结
  • 原文地址:https://www.cnblogs.com/dinghing154/p/2612593.html
Copyright © 2011-2022 走看看