开发者

Merge two UIView into one UIImage

开发者 https://www.devze.com 2023-02-19 18:08 出处:网络
I\'ve got two UIImageView: the first one is laying on the top of the other (eg. an overlay). I want now to take a screenshot of the whole thing.

I've got two UIImageView: the first one is laying on the top of the other (eg. an overlay). I want now to take a screenshot of the whole thing. Note that before that step, I allow the user to change the overlay by panning,scaling and ROTATING it, so I must 开发者_JAVA技巧keep track of his editing.

So, here's the homework:

  1. rotating the context basing on the view's transform rotation value
  2. positioning on the origin, where the user finished to pan the overlay
  3. calculate the size of the overlay view (it's always a rectangle, however!)

I'm gonna merge them inside a similar piece of code:

UIGraphicsBeginImageContext...
...
UIImage *result = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext();

but... what does "best fit" instead of the "..."?

Example code is well accepted! Thanks


UIGraphicsBeginImageContext(firstImage.size);
[firstImage drawAtPoint:CGPointMake(0,0)];
[secondImage drawAtPoint:CGPointMake(0,0)];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消