• 绘制纹理


    #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);
    }

  • 相关阅读:
    Golang 函数
    关于Golang中database/sql包的学习
    golang第三方库goconfig的使用
    golang []byte和string相互转换
    golang xorm应用
    PHPExcel 导入
    贝叶斯定理
    myFocus 焦点图/轮播插件
    Maven 安装与使用(一)
    Javascript -- toFixed()函数
  • 原文地址:https://www.cnblogs.com/riskyer/p/3397904.html
Copyright © 2020-2023  润新知