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

标签 objective-c ios merge uiimage

我正在开发一个 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/

相关文章:

iphone - 在联系页面添加地址簿

ios - 嵌入式 Vimeo 视频无法通过 iOS 模拟器在 iPad Safari 上运行

python - 如何在 Pandas 中合并 "(df1 & not df2)"数据帧?

ios - 核心数据 : Turning Objects into Faults after saving them?

ios - 在 'ViewController' 类型的对象上找不到属性引用?

objective-c - 如何在 Cocoa OSX 中创建水平滚动照片集?

python - 根据索引和列合并/连接两个数据框

ios - 为什么我会收到指针错误?

ios - 关联类型错误 : Cannot assign a value of type '[SpecificType]' to a value of type '[NameOfTypeAlias]'

python - 合并字典,保留重复键的值