【问题标题】:How to move the image on the CGContextRef如何在 CGContextRef 上移动图像
【发布时间】:2012-12-25 01:48:29
【问题描述】:

已在 CGContextRef 上绘制了图像:

CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);

在另一个函数中,我想将图像移动到矩形

CGRectMake(100, 100, width, height);

我该怎么办?

void func(CGContextRef context)//there is just one parameter
{
    //move  the image
}

【问题讨论】:

    标签: ios cgimageref cgcontextref


    【解决方案1】:

    一旦您进入上下文,就无法撤消。您可以在之前的图像上绘制,也许使用纯色来匹配背景。我不知道您为什么要绘制到上下文然后移动它。

    我将假设绘制图像的第一个函数调用定位它的第二个函数。如果是这种情况,您可以让第二个函数简单地对上下文应用平移变换,然后让第一个函数在调用第二个函数后绘制图像。

    【讨论】:

      【解决方案2】:

      试试这个

      void func(CGContextRef context, CGFloat x, CGFloat y)
      {
          CGContextDrawImage(context, CGRectMake(x,y, width, height), image);
       }
      

      【讨论】: