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)开发者_Go百科. 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?
To programatically put one image data over (drawn above) another image, and get the composite as a new UIImage:
overlap one image over another
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.
精彩评论