gpt4 book ai didi

objective-c - 如何在 iPhone SDK 的 Objective-C 中合并两个 UIImage 对象

转载 作者:可可西里 更新时间:2023-11-01 04:36:16 25 4
gpt4 key购买 nike

我正在开发一个 iPhone 应用程序,我想合并两个 UIImage(leftImage 和 rightImage)。任何人都可以建议如何在它们之间没有界限的情况下做到这一点吗?

我目前正在这样做:

- (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((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(firstWidth, 0, secondWidth, secondHeight)];
[second drawInRect:CGRectMake(firstWidth, 0, secondWidth, secondHeight) blendMode:kCGBlendModeNormal alpha:1.0];

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

// end context
UIGraphicsEndImageContext();

return newImage;

}

但是它在两个图像之间创建了一条细线。我不想要这个分隔符,就像Splitcam一样做到了。

我该怎么做?

最佳答案

只需让边缘重叠一个像素即可。

[second drawInRect:CGRectMake(firstWidth-1, 0, secondWidth, secondHeight) 
blendMode:kCGBlendModeNormal alpha:1.0];

关于objective-c - 如何在 iPhone SDK 的 Objective-C 中合并两个 UIImage 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12211849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com