zoukankan      html  css  js  c++  java
  • 绘制纹理

    #define H_PATTERN_SIZE 16
    #define V_PATTERN_SIZE 18
    #define H_PSIZE 16
    #define V_PSIZE 18

    void MyDrawColoredPattern (void *info, CGContextRef myContext)
    {
        CGFloat subunit = 5; // the pattern cell itself is 16 by 18
      
        CGRect  myRect1 = {{0,0}, {subunit, subunit}},
        myRect2 = {{subunit, subunit}, {subunit, subunit}},
        myRect3 = {{0,subunit}, {subunit, subunit}},
        myRect4 = {{subunit,0}, {subunit, subunit}};
      
        CGContextSetRGBFillColor (myContext, 0, 0, 1, 1);
        CGContextFillRect (myContext, myRect1);
        CGContextSetRGBFillColor (myContext, 0, 0.5, .4, 1);
        CGContextFillRect (myContext, myRect2);
        CGContextSetRGBFillColor (myContext, 0, 1, 0, 1);
        CGContextFillRect (myContext, myRect3);
        CGContextSetRGBFillColor (myContext, .5, 0, 1.5, 1);
        CGContextFillRect (myContext, myRect4);
    }

    void MyColoredPatternPainting (CGContextRef myContext,
                                   CGRect rect)
    {
        CGPatternRef    pattern;// 1
        CGColorSpaceRef patternSpace;// 2
        CGFloat        alpha = 1,// 3
        width, height;// 4
        staticconst    CGPatternCallbacks callbacks = {0, // 5
            &MyDrawColoredPattern,
            NULL};
      
        CGContextSaveGState (myContext);
      
    //    CGContextTranslateCTM(myContext, rect.origin.x, rect.origin.y);
    //    CGContextTranslateCTM(myContext, 0, rect.size.height);
    //    CGContextScaleCTM(myContext, 1.0, -1.0);
    //    CGContextTranslateCTM(myContext, -rect.origin.x, -rect.origin.y);
      
      
        patternSpace = CGColorSpaceCreatePattern (NULL);// 6
        CGContextSetFillColorSpace (myContext, patternSpace);// 7
        CGColorSpaceRelease (patternSpace);// 8
      
        pattern = CGPatternCreate (NULL, // 9
                                   CGRectMake (0, 0, H_PSIZE, V_PSIZE),// 10
                                   CGAffineTransformMake (1, 0, 0, 1, 0, 0),// 11
                                   H_PATTERN_SIZE, // 12
                                   V_PATTERN_SIZE, // 13
                                   kCGPatternTilingConstantSpacing,// 14
                                   true, // 15
                                   &callbacks);// 16
      
        CGContextSetFillPattern (myContext, pattern, &alpha);// 17
        CGPatternRelease (pattern);// 18
        CGContextFillRect (myContext, rect);// 19
        CGContextRestoreGState (myContext);
    }

  • 相关阅读:
    ionic入门之AngularJS扩展基本布局
    ionic入门之AngularJS扩展(一)
    test
    面试题小整理
    使用Code first 进行更新数据库结构(数据迁移)
    SQL模糊查询与删除多条语句复习
    GridView 根据要求显示指定值
    个人工作记录---工作中遇到的sql查询语句解析
    数据库,inner join,left join right join 的区别
    利用set实现去重
  • 原文地址:https://www.cnblogs.com/riskyer/p/3397904.html
Copyright © 2011-2022 走看看