Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay an image over another image in iOS

Tags:

i am displaying thumbnail images from youtube in my iOS app. which upon click, will go to youtube.

I need a way of overlaying a play button onto those images. What might be the most straightforward way of doing so?

Also, the images are remotely loaded onto a table, so performance is a big consideration

like image 450
meow Avatar asked Sep 05 '11 21:09

meow


People also ask

How do I overlay an image on another image?

You can easily put a photo on top of another photo using Fotor, a free online photo editor. Simply drag and drop the image you want to overlay into Fotor- this will become your background picture. Then add a new image over it. You can adjust the transparency levels to blend two images together perfectly.

Can you add an image to another image on iPhone?

The iPhone doesn't come pre-installed with any features that allow you to merge pictures together. But you can do what you want with the Shortcuts app. Shortcuts are built-in automation tools on the iPhone. It can merge pictures together.


2 Answers

If you are concerned with table scrolling performance, retrieve the thumbnail and paint the play button over it.

+(UIImage*) drawImage:(UIImage*) fgImage               inImage:(UIImage*) bgImage               atPoint:(CGPoint)  point {     UIGraphicsBeginImageContextWithOptions(bgImage.size, FALSE, 0.0);     [bgImage drawInRect:CGRectMake( 0, 0, bgImage.size.width, bgImage.size.height)];     [fgImage drawInRect:CGRectMake( point.x, point.y, fgImage.size.width, fgImage.size.height)];     UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();     UIGraphicsEndImageContext();      return newImage; } 
like image 193
Jano Avatar answered Oct 14 '22 05:10

Jano


Swift 2.2 Version

  static func drawImage(image foreGroundImage:UIImage, inImage backgroundImage:UIImage, atPoint point:CGPoint) -> UIImage{     UIGraphicsBeginImageContextWithOptions(backgroundImage.size, false, 0.0)     backgroundImage.drawInRect(CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height))     foreGroundImage .drawInRect(CGRectMake(point.x, point.y, foreGroundImage.size.width, foreGroundImage.size.height))     let newImage = UIGraphicsGetImageFromCurrentImageContext()     UIGraphicsEndImageContext()     return newImage   } 
like image 23
creative_rd Avatar answered Oct 14 '22 04:10

creative_rd