如何将两个图像组合成一个图像对象? [英] How can I combine two images into one image object?
问题描述
如何组合两张图片?
我的意思是我有两个图片:一个小,另一个大。我想在一个特定的点添加小图像到大的,我需要一个 UIImage
作为结果。
I mean I have two images: one small and another big one. I want to add small image onto big one at a specific point and I need to get an UIImage
as the result.
我尝试过 CGCreateImageFromMask
,但这使小图片完全覆盖更大的图片。
I have tried CGCreateImageFromMask
but that makes small image to cover bigger image completely.
推荐答案
您将需要使用 UIGraphicsBeginImageContext()
生成 CGContextRef
,然后使用 UIGraphicsGetCurrentContext()
获取对它的引用。
You'll want to use UIGraphicsBeginImageContext()
to generate a CGContextRef
, then use UIGraphicsGetCurrentContext()
to get a reference to it.
现在将当前图像绘制到上下文中。完成后,使用 UIGraphicsGetImageFromCurrentContext()
从该上下文中生成 UIImage
,并且 UIGraphicsEndImageContext()
清理。
Now draw your current images into the context. When you're done, use UIGraphicsGetImageFromCurrentContext()
to generate an UIImage
from that context, and UIGraphicsEndImageContext()
to clean up.
请参阅 Apple的UIKit函数参考文档。
这篇关于如何将两个图像组合成一个图像对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!