在保存旋转的同时将2个UIImage保存为一个,调整信息和质量

我想保存2个用户移动,resize和旋转的UIImage。 问题是我不想使用“printscreen one”这样的function,因为这会使两个图像的质量(分辨率)都大打折扣。

Atm我使用这样的东西:

UIGraphicsBeginImageContext(image1.size); [image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; [image2 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

但是它只是添加两个图像,它们的旋转,resize和移动不在这里操作。 有人可以帮忙考虑这三个方面的编码吗? 任何帮助表示赞赏!

我最大的感谢之一:)

编辑:图像可以旋转和缩放用户(处理触摸事件)!

开始绘制之前,必须设置上下文的变换以匹配imageView的变换。

 CGAffineTransform transform = CGAffineTransformIdentity; transform = CGAffineTransformTranslate(transform, boundingRect.size.width/2, boundingRect.size.height/2); transform = CGAffineTransformRotate(transform, angle); transform = CGAffineTransformScale(transform, 1.0, -1.0); CGContextConcatCTM(context, transform); // Draw the image into the context CGContextDrawImage(context, CGRectMake(-imageView.image.size.width/2, -imageView.image.size.height/2, imageView.image.size.width, imageView.image.size.height), imageView.image.CGImage); // Get an image from the context rotatedImage = [UIImage imageWithCGImage: CGBitmapContextCreateImage(context)]; 

并检查出从旋转的UIImageView创build一个UIImage 。

编辑:如果你不知道图像的旋转angular度,你可以从UIImageView的图层属性的变换:

 UIGraphicsBeginImageContext(rotatedImageView.image.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGAffineTransform transform = rotatedImageView.transform; transform = CGAffineTransformScale(transform, 1.0, -1.0); CGContextConcatCTM(context, transform); // Draw the image into the context CGContextDrawImage(context, CGRectMake(0, 0, rotatedImageView.image.size.width, rotatedImageView.image.size.height), rotatedImageView.image.CGImage); // Get an image from the context UIImage *newRotatedImage = [UIImage imageWithCGImage: CGBitmapContextCreateImage(context)]; UIGraphicsEndImageContext(); 

你将不得不玩转换matrix中心的图像在上下文中,你也将不得不计算旋转的图像的边界矩形或它将被裁剪在angular落(即rotateImageView.image.size不大足以包含自身的旋转版本)。

尝试这个:

 UIImage *temp = [[UIImage alloc] initWithCGImage:image1 scale:1.0 orientation: yourOrientation]; [temp drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; 

同样对于image2。 旋转和resize分别按方向和比例进行处理。 yourOrientation是一个UIImageOrientation枚举variables,可以有一个从0到7的值(检查这个苹果文档在不同的UIImageOrientation值)。 希望能帮助到你…

编辑:要处理旋转,只需要为所需的旋转写入所需的方向。 您可以左右旋转90度或垂直/水平翻转。 例如,在苹果文档中,UIImageOrientationUp为0,UIImageOrientationDown为1等等。 看看我的github回购一个例子。