您好,我正在开发需要合并两个图像的应用程序,通过合并两个图像,我的图像尺寸为 320*240 我希望尺寸为 320 * 480。我如何以编程方式执行此操作。以下是图片
============================================= ====================================
最佳答案
刚刚对此进行了测试,根据您正在使用的图像的大小创建上下文并将它们绘制在彼此之上(假设它们的宽度相同):
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 - 在iphone中以编程方式将两个图像合并到一个图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18273271/