这个函数绘制图片,但坐标系统原点在左上角,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, 0, rect.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实现想要的功能。

相关文章:

  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
  • 2021-12-07
  • 2021-09-25
  • 2021-10-28
  • 2021-11-04
  • 2021-08-01
猜你喜欢
  • 2021-08-19
  • 2021-11-11
  • 2021-10-01
  • 2022-01-08
  • 2022-12-23
相关资源
相似解决方案