从 2 个 UIImages 和标签创建 UIImage [英] Create UIImage from 2 UIImages and label

查看:22
本文介绍了从 2 个 UIImages 和标签创建 UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个很大的 UIImage.在这个 UIImage 上我又得到了一个,女巫实际上是一个面具.还有一个 - 我在这个面具上得到了 UILabel !女巫是图片的文字.

I got one big UIImage. Over this UIImage i got one more, witch is actually a mask. And one more - i got UILabel over this mask! Witch is text for the picture.

我想将所有这些部分组合在一个 UIImage 中以将其保存到相机胶卷中!

I want to combine all this parts in one UIImage to save it to Camera Roll!

我该怎么做?

更新.我应该如何添加 UITextView?

UPD. How should i add UITextView?

我发现:

[[myTextView layer] renderInContext:UIGraphicsGetCurrentContext()];

但是这个方法没有将 myTextView 放在正确的位置.

But this method doesn't place myTextView on the right place.

推荐答案

创建两个 UIImage 对象和一个 UILabel 对象,然后使用 drawInRect:方法

create two UIImage objects and one UILabel objects then use drawInRect: method

//create image 1

UIImage *img1 = [UIImage imageNamed:@"image1.png"];

//create image 2    

UIImage *img2 = [UIImage imageNamed:@"image2.png"];

// create label

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50,50 )];

//set you label text

[label setText:@"Hello"];

// use UIGraphicsBeginImageContext() to draw them on top of each other

//start drawing
UIGraphicsBeginImageContext(img1.size);

//draw image1

[img1 drawInRect:CGRectMake(0, 0, img1.size.width, img1.size.height)];

//draw image2

[img2 drawInRect:CGRectMake((img1.size.width - img2.size.width) /2, (img1.size.height- img2.size.height)/2, img2.size.width, img2.size.height)];

//draw label

[label drawTextInRect:CGRectMake((img1.size.width - label.frame.size.width)/2, (img1.size.height - label.frame.size.height)/2, label.frame.size.width, label.frame.size.height)];

//get the final image

UIImage *resultImage  = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

resultImageUIImage 包含所有图像和标签作为一个图像.之后,您可以将其保存在任何您想要的位置.

The resultImage which is UIImage contains all of your images and labels as one image. After that you can save it where ever you want.

希望有所帮助...

这篇关于从 2 个 UIImages 和标签创建 UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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