【问题标题】:How can I merge two images after change the 3D transform? [duplicate]更改 3D 变换后如何合并两个图像? [复制]
【发布时间】:2012-12-20 15:31:39
【问题描述】:

可能重复:
How to merge the perspective image(3D Transform)?

更改 3D 变换后如何合并两个图像?我正在使用两张图片

(i) 背景图片为普通图片。

(ii) 前景图像改变 3D 变换。

现在我合并两个图像。但没有合并图像,我正在使用下面的代码。此代码在没有 3D 变换的情况下工作正常。

UIGraphicsBeginImageContext(backgroundImageView.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[imageView.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
return newImage;

我搜索了很多,但是 3D 转换图像不支持该图层。

如何获得此功能。我真的必须在我的应用程序上使用这个功能。任何想法、源代码、建议、建议,随时欢迎。请帮我。

【问题讨论】:

  • 请不要重复同一个问题。如果您不喜欢第一次提出的答案,您可以不接受您在该问题上接受的答案。如果您需要更多帮助,可以针对您的原始问题提供悬赏。
  • 另外,看看this answer

标签: iphone ios uiimage


【解决方案1】:

试试这个。

- (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second
{
 // get size of the first image
 CGImageRef firstImageRef = first.CGImage;
 CGFloat firstWidth = CGImageGetWidth(firstImageRef);
 CGFloat firstHeight = CGImageGetHeight(firstImageRef);

 // get size of the second image
 CGImageRef secondImageRef = second.CGImage;
 CGFloat secondWidth = CGImageGetWidth(secondImageRef);
 CGFloat secondHeight = CGImageGetHeight(secondImageRef);

 // build merged size
 CGSize mergedSize = CGSizeMake(MAX(firstWidth, secondWidth), MAX(firstHeight, secondHeight));

 // capture image context ref
 UIGraphicsBeginImageContext(mergedSize);

 //Draw images onto the context
 [first drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
 [second drawInRect:CGRectMake(0, 0, secondWidth, secondHeight)]; 

 // assign context to new UIImage
 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

 // end context
 UIGraphicsEndImageContext();

 return newImage;
}

【讨论】:

  • 谢谢 HDdeveloper...但是此代码仅适用于 3D 变换。请有其他想法。
猜你喜欢
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-19
  • 2012-12-21
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
相关资源
最近更新 更多