zoukankan      html  css  js  c++  java
  • 讨论CGContextDrawImage

    LINK Address:http://www.cnblogs.com/delonchen/archive/2011/06/12/CGContextDrawImage.html

    讨论CGContextDrawImage

    这个函数绘制图片,但坐标系统原点在左上角,y方向向下的(坐标系A),但在Quartz中坐标系原点在左下角,y方向向上的(坐标系B)。图片绘制也是颠倒的。

    要达到预想的效果必须变换坐标系,代码如下:

    void drawImage(CGContextRef context, CGImageRef image , CGRect rect){

       CGContextSaveGState(context);

     

            CGContextTranslateCTM(context, rect.origin.x, rect.origin.y);//4

            CGContextTranslateCTM(context, 0rect.size.height);//3

            CGContextScaleCTM(context, 1.0, -1.0);//2

            CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);//1

            CGContextDrawImage(context, rect, image);

     

            CGContextRestoreGState(context);

    }

    A到B变换 通过1->2->3->4步骤实现的,这样好理解些

    通常我会用UIImage drawInRect实现想要的功能。

  • 相关阅读:
    Python批量删除字符串中两个字符中间值
    2020年大三下学期第十周学习心得
    2020年大三下学期第九周学习心得
    2020.2.4
    2020.2.3
    2020.2.2
    2020.2.1
    签到六(开发)
    签到五(开发)
    签到四(开发)
  • 原文地址:https://www.cnblogs.com/xingchen/p/2166197.html
Copyright © 2011-2022 走看看