ios - 如何移动 CGContextRef 上的图像

标签 ios cgimageref cgcontextref

已在 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 - 如何移动 CGContextRef 上的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14027064/

相关文章:

ios - 如何在 Swift 中合并和格式化数组? (X 和 Y 坐标数组)

ios - CGImageCreate 给出完全黑色或无图像或崩溃

ios - 如何在iOS中清除CGContext中的圆圈

iphone - 如何清除 CGContextRef?

ios - 在 ViewController 之间显示叠加 View

ios - 如何在播放同一个本地视频时同步多个 AVPlayer

ios - Swift - 通知中心

ios - 如何将从 CGImageRef 创建的 UIImage 对象转换为原始数据并再次转换回来

swift - CGImageSource 到 CGImage?