开发者

iPhone SDK - How to draw a UIImage onto another UIImage?

开发者 https://www.devze.com 2022-12-21 06:07 出处:网络
I have several rectangular images (in landscape and portrait mode) and want to draw them o开发者_运维知识库ntoa transparent square image, so that all images became the same size without cropping them.

I have several rectangular images (in landscape and portrait mode) and want to draw them o开发者_运维知识库nto 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?

Thanks for any hints.


  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:].

Code examples can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消