保存两个重叠的UIImage [英] Saving two Overlapping UIImage

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

问题描述

我正在尝试在iPhone上构建相框应用程序.我在png格式中将框架制成透明的,然后通过选择照片并将其放置在界面构建器中的框架层后面.

I am trying to build a photo frame application on iphone. I made the frame it is transparent in png formate, then by choosing photos and was placed behind the frame layer in the interface builder.

在界面生成器中,它们放置得很好并且非常合适.现在我的问题是如何将它们保存到一张照片中.

In interface builder they are placed well and fit well. Now my problem is how can i save them into one picture.

这是我拥有的代码,但是节省的部分一直崩溃.

Here is the code i have, but the saving part keep crashing.

-(IBAction) saveImage:(id)sender{

    imagefront .backgroundColor = [UIColor clearColor]; //This sets your backgroung to transparent. 
    imagefront.opaque = NO;
    [imageView bringSubviewToFront:imagefront];

    UIImage *overlappedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();


    UIImageWriteToSavedPhotosAlbum(overlappedImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}

Imagefront是相框,而imageView是照片.

Imagefront is the photoframe while imageView is the photo.

谢谢.

推荐答案

您当前的方法不正确.您将需要执行此操作以获取图像.

Your current approach is incorrect. You will need to do this to get the image.

UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();

这是假设 imageView imageFront 作为其子视图,如您所发布的代码所建议.

This is assuming that imageView has imageFront as its subview as suggested by the code you've posted.

这篇关于保存两个重叠的UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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