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

前端 未结 1 964
心在旅途
心在旅途 2021-02-10 05:43

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 croppi

相关标签:
1条回答
  • 2021-02-10 06:29
    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 讨论(0)
提交回复
热议问题