无法将两个图像合并为一个

时间:2013-03-30 02:07:05

标签: iphone ios objective-c xcode image

我正在尝试将两个图像合并为一个,并将该图像保存到相机胶卷上。但它只是显示一个空白图像。有人可以帮忙吗?

我的代码:

-(void)SaveFinalImage{    
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *savedImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(savedImg, nil, nil, nil);     
}

1 个答案:

答案 0 :(得分:3)

我在我的应用中使用了这个。

UIImage *bottomImage = [UIImage imageNamed:@"bottom.png"]; //background image
UIImage *image       = [UIImage imageNamed:@"top.png"]; //foreground image

CGSize newSize = CGSizeMake(width, height);
UIGraphicsBeginImageContext( newSize );

// Use existing opacity as is
[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Apply supplied opacity if applicable
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

了解更多关于同一主题的相关答案。 iOS - Merging two images of different size