在iphone中以编程方式将两个图像合并到一个图像上 [英] Merge Two Image on to one Image programmatically in iphone

查看:81
本文介绍了在iphone中以编程方式将两个图像合并到一个图像上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发需要合并两个图像的应用程序,我的图像大小是320 * 240通过合并两个图像我希望大小为320 * 480。我怎么能这样做呢?以下是图片

Hello I am developing the application which requires to merge two Image , My image size are 320*240 by merging both Image I want the size to be 320 * 480 . How can i do this programitically . Following are the Images

========== ================================================== =======================

===================================================================================

推荐答案

刚刚测试过这个,创建你的上下文根据您正在使用的图像的大小并将它们绘制在一起(这假设它们的宽度相同):

Just tested this, create your context based on the sizes of the images you are working with and draw them on top of each other (this assumes they are the same width):

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

CGSize size = CGSizeMake(image1.size.width, image1.size.height + image2.size.height);

UIGraphicsBeginImageContext(size);

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

UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

//Add image to view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, finalImage.size.width, finalImage.size.height)];
imageView.image = finalImage;
[self.view addSubview:imageView];

这篇关于在iphone中以编程方式将两个图像合并到一个图像上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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