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实现想要的功能。

  • 相关阅读:
    机器学习数学符号解释
    JVM Guide
    Mysql优化
    JAVA必会算法--冒泡排序
    HashMap-JDK源码阅读
    vue 下载文件
    CommonMethod
    log4net 写日志
    WebAPI 封装返回值
    二, .NET Core 微服务学习 ——集中式代理-Nginx
  • 原文地址:https://www.cnblogs.com/xingchen/p/2166197.html
Copyright © 2011-2022 走看看