[英]iPhone screenshot of transformed UIImageView
我的问题是
我有一个UIImageView,用户可以自由旋转。
我现在希望能够仅捕获此新旋转的图像。
不幸的是,下面的代码可以截取单个视图的屏幕快照,但是很遗憾地返回了处于未旋转状态的视图的屏幕快照。
-(IBAction)captureScreen:(id)sender
{
UIGraphicsBeginImageContext(imgView.frame.size);
[imgView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
}
有什么想法可以保留这里的轮换吗?
在包含旋转视图的视图上使用代码,而不在旋转视图本身上使用代码。
尝试这个?
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
NSString *yourPath;
NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:yourPath];
[UIImageJPEGRepresentation(viewImage, 1.0) writeToFile:jpgPath atomically:YES];
我假设您正在通过UIImage方法旋转图像。 这样做的问题是它并没有真正旋转图像本身,只是在告诉谁绘制图像以横向绘制图像。
我建议您实际上使用核心图形旋转图像,然后以这种方式保存结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.