Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在保存旋转、调整信息大小及其质量的同时将2个UIImage保存为一个_Objective C_Ios_Cocoa Touch_Uiimage_Zooming - Fatal编程技术网

Objective c 在保存旋转、调整信息大小及其质量的同时将2个UIImage保存为一个

Objective c 在保存旋转、调整信息大小及其质量的同时将2个UIImage保存为一个,objective-c,ios,cocoa-touch,uiimage,zooming,Objective C,Ios,Cocoa Touch,Uiimage,Zooming,我想保存2个用户移动、调整大小和旋转的UIImage。问题是,我不想使用任何“printscreen one”这样的函数,因为它会使两幅图像的质量(分辨率)损失很多 我用的是这样的东西: UIGraphicsBeginImageContext(image1.size); [image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; [image2 drawInRect:CGRectMake(0, 0, i

我想保存2个用户移动、调整大小和旋转的UIImage。问题是,我不想使用任何“printscreen one”这样的函数,因为它会使两幅图像的质量(分辨率)损失很多

我用的是这样的东西:

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();
然而,ofc it只是添加了两个图像,它们的旋转、调整大小和移动在此不进行操作。有人能帮助我们在编码时考虑这三个方面吗?感谢您的帮助

我最衷心的感谢:)

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

试试这个:

UIImage *temp = [[UIImage alloc] initWithCGImage:image1 scale:1.0 orientation: yourOrientation];
[temp drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
类似于图2。旋转和调整大小分别由方向和比例处理。yourOrientation是UIImageOrientation枚举变量,可以具有0-7之间的值(在不同的UIImageOrientation值上检查此项)。希望对你有帮助


编辑:要处理旋转,只需为所需的旋转写入所需的方向。您可以向左/向右旋转90度或垂直/水平翻转。例如,在apple文档中,UIImageOrientationUp为0,UIImageOrientationDown为1,依此类推。查看my repo以获取一个示例。

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

i、 e

然后退房

编辑:如果不知道图像的旋转角度,可以从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();

您必须使用变换矩阵在上下文中使图像居中,还必须计算旋转图像的边界矩形,否则将在拐角处对其进行裁剪(即RotateImage.View.image.size不够大,无法包含旋转后的图像本身).

苹果文档末尾提供了不同的方向,链接如上。不,这是错误的。我的用户可以用2个手指触摸旋转图像,与旋转相同-用户可以这样做。您的代码根据程序员的需要而不是用户的需要旋转图像。我想我只需要抓拍屏幕。非常感谢您的想法和帮助,tho!:)哦…我明白了。您必须使用CGAffineTransformRotate方法。看看这个。它可以处理多点触摸和同时旋转,而不是标签,使用ImageView我有我的旋转方法,我只是没有合适的方法来保存旋转和缩放的图像:)我不确定,但我认为当你知道移动图像的角度时,你的方法是有效的。我不知道用户将如何旋转图像,因为他用拇指来旋转。我的代码就是这样。我还可以从UIImageView中获取转换。这是一个仿射变换矩阵,与我在前几行代码中创建的矩阵相同。我认为唯一的区别是UIView的y轴在屏幕顶部交叉,而CoreGrahics/Quartz的y轴在屏幕底部交叉。我还没有试过,但是你应该能够从视图中得到矩阵,对其应用比例(上面的第4行),然后在上下文中绘制。希望这是有道理的。DaveHave尝试了这一点,效果很好-将在我的答案中添加更多示例代码。+1表示“在开始绘制之前,您必须设置上下文的转换以匹配imageView的转换。”。。。
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();