0

enter image description here

How to merge these two images(see attached image).I am using the below code. Its working for ordinary images not for 3D transform images. How to handle this issue. I have searched lot of times still not getting the proper result. Please help me. Thanks in advance.

UIImage *mergedImage;
UIGraphicsBeginImageContext(backgroundImageView.frame.size);
[backgroundImageView.layer  renderInContext:UIGraphicsGetCurrentContext()]; //bacgroundImageView here
mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Olotiar
  • 3,225
  • 1
  • 18
  • 37
Mani
  • 1,310
  • 1
  • 20
  • 40
  • I see that you're using my GPUImage framework here at some point (those are the sample images I ship with the framework). Why not use a blend filter from that, combined with a transform filter, instead of working with UIViews? – Brad Larson Sep 18 '12 at 19:15

2 Answers2

0

You could create a CGImageRef that contain the distorted image to put on top, (with the background of that image being 0% alpha) that way you could blend the images using your above code.

So what you are truly looking for is how to apply a 3D transform to an image. More precisely, as you are looking for "perspective" in you own words, you are looking on how to warp an homography to an image.

The CoreImage programming guide specify that CIPerspectiveTransform is the way to go, unfortunately for you this is not available on iOS as of iOS 5.1.

So you are left with a few choices :

  • If you want to display only the result blend and not manipulate it, you can use two UIImageViews on top of each other, the one containing the perspective image being transformed using a cleverly designed CATransform3D

  • If you absolutely need to blend the images, you will need to use another framework such as OpenCV (warpPerspective()is the function you are looking for) or OpenGL ES

Olotiar
  • 3,225
  • 1
  • 18
  • 37
0

Unfortunately, renderInContext: only flattens 2D transforms. It cannot flatten 3D transforms applied to layers. There is no way around this.

sudo rm -rf
  • 29,408
  • 19
  • 102
  • 161