iPhone SDK - 如何将UIImage绘制到另一个UIImage上? [英] iPhone SDK - How to draw a UIImage onto another UIImage?

查看:107
本文介绍了iPhone SDK - 如何将UIImage绘制到另一个UIImage上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个矩形图像(在横向和纵向模式下)并且想要将它们绘制到透明的方形图像上,这样所有图像都会变成相同的大小而不会裁剪它们。我如何创建一个透明的UIImage并在另一个上面绘制另一个?

I have several rectangular images (in landscape and portrait mode) and want to draw them onto a transparent square image, so that all images became the same size without cropping them. How would I create a transparent UIImage and draw another on top?

感谢任何提示。

推荐答案


  1. 使用 CGBitmapContextCreate 创建位图图形上下文。您需要在此处确定所得合成图像的大小。您可以将其视为一种画布。

  2. 使用 CGContextDrawImage 绘制图像。这将把图像绘制到相同的上下文中。

  3. 完成将所有图像绘制到同一个上下文后,使用 CGBitmapContextCreateImage 创建一个图像。 code>。

  4. 将步骤#3中的Core Graphics图像转换为带有 [UIImage imageWithCGIImage:] 的UIImage。

  1. Create a bitmap graphic context with CGBitmapContextCreate. You'll need to determine what the size of the resulting composite image here. You can think of this as a sort of canvas.
  2. Draw the images using CGContextDrawImage. This will draw images onto the same context.
  3. Once you're done drawing all the images into the same context, create an image from that context with CGBitmapContextCreateImage.
  4. Convert the Core Graphics image from step #3 into a UIImage with [UIImage imageWithCGIImage:].

可以找到代码示例此处

这篇关于iPhone SDK - 如何将UIImage绘制到另一个UIImage上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆