转换后的UIImageView的iPhone截图

时间:2012-01-23 09:54:19

标签: iphone ios cocoa-touch uikit uiimageview

我的问题是这个 -

我有一个UIImageView,用户可以自由旋转。

我现在希望能够捕获这个新旋转的图像。

下面的代码,可以截取单个视图的屏幕截图,不幸的是返回 视图处于未旋转状态的屏幕截图。

-(IBAction)captureScreen:(id)sender
{
    UIGraphicsBeginImageContext(imgView.frame.size);
    [imgView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
}

任何想法如何在这里保留轮换?

3 个答案:

答案 0 :(得分:0)

在包含旋转视图的视图上使用您的代码,而不是在旋转视图本身上。

答案 1 :(得分:0)

试试这个?

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];

答案 2 :(得分:0)

我假设您正在通过UIImage方法旋转图像。问题在于它并没有真正旋转图像本身,它只是告诉任何人绘制它以横向绘制它。

我建议您实际使用核心图形旋转图像,然后就可以保存结果