thomashw
thomashw

Reputation: 956

Overlay an image on a background

I'm wondering how to create a new UIImage by overlaying one image overtop of another image?

What I'm doing is downloading an image from a web service. I'd then like to place this image over top of a background image (the background image is slightly taller/wider than the downloaded image). I'd then like to use this new image for the image of an annotation view on a map, so I need to create one UIImage from the downloaded image and the background.

How can I do this?

Upvotes: 0

Views: 362

Answers (2)

RabinDev
RabinDev

Reputation: 658

To programatically put one image data over (drawn above) another image, and get the composite as a new UIImage:

overlap one image over another

Upvotes: 1

Hermann Klecker
Hermann Klecker

Reputation: 14068

Create a UIImage object to store the image data that you downloaded. Use the constructor [UIImage imageWithData:data] for that.

Create a new UIImageView object.

Assign the UIImage object to the views' image property. You could do that in one go.

UIImageView *newImageView = [UIImage imageWithData:data];

(assuming that data is of NSData and contains the received data)

Then set the frame of your newImageView properly in the coordinate system of its superview and add it to its superview or vice versa.

Upvotes: 0

Related Questions