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

  • 相关阅读:
    基础编程练习题第一波
    TYVJ 1541 八数码
    NOIP 2014 寻找道路
    NOIP2014 解方程
    POJ 3213 矩阵乘法(优化)
    POJ 1523 Tarjan求割点
    POJ 3237 树链剖分+线段树
    SPOJ 375 树链剖分
    NOIP 2012 T2 国王游戏 (贪心+高精)
    POJ 1364 差分约束
  • 原文地址:https://www.cnblogs.com/riskyer/p/3397904.html
Copyright © 2011-2022 走看看