将两个UIImage合并为1来保存图书馆 [英] Merging two UIImage into 1 to be savedtolibrary

查看:90
本文介绍了将两个UIImage合并为1来保存图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何将2 uiimage合并为1?我想将最终产品保存到库中。为了保存图像,我正在使用UI按钮。这是我如何保存UIImageview.image的片段。

I would like to know how can I merge 2 uiimage into 1? I would like to save the end product to the library. For saving images I'm using a UI button. Here's snippet of how I save a UIImageview.image.

-(IBAction)getPhoto:(id)sender  {

UIImage* imageToSave = imageOverlay.image;

UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil);
}

我看过网上看过UIGraphicsBeginImageContext。找到了一个例子,但我无法理解如何将它实际应用到我的。这是我到目前为止所得到的。

I've looked online and read about UIGraphicsBeginImageContext. Found an example but I couldn't understand how to actually apply it to mine. Here's the one I've got so far.

- (UIImage*)addImage:(UIImage *)image secondImage:(UIImage *)image2 
{
UIGraphicsBeginImageContext(image.size);
[image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
[image2 drawInRect:CGRectMake(10,10,image2.size.width,image2.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;
}

现在我有2个UIImageviews,它们是imageOverlay.image和imageView.image。如果我使用上面的方法如何将返回值分配给UIImageWriteToSavedPhotoAlbum?希望有人能指出我正确的方向。

Right now I have 2 UIImageviews which is imageOverlay.image and imageView.image. If I use the method above how to assign the return value to UIImageWriteToSavedPhotoAlbum? Hope someone can point me to the right direction.

非常感谢。

推荐答案

看起来你的头文件中没有方法的标题,在运行IBAction的类/视图控制器的.h文件中,添加方法的第一行, - (UIImage *)addImage:...并以a结尾;在@end之前。这应该工作,虽然你必须在同一个.h文件的.m文件中实现它。

Seems like you don't have the header for the method in your header file, in the .h file of the class/view controller from which you're running the IBAction, add the first line of your method, -(UIImage*) addImage:... And end it with a ; before the @end. That should work, though you'd have to implement it in the .m file of the same .h file somewhere.

这篇关于将两个UIImage合并为1来保存图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆