How to merge the perspective image(3D Transform)?

天大地大妈咪最大 提交于 2019-11-27 08:48:33

问题


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();

回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/12457047/how-to-merge-the-perspective-image3d-transform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!