2012-01-23 100 views
0

我的问题是这样的 -iPhone屏幕截图转换UIImageView

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

我现在想要捕捉这个新旋转的图像。

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

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

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

+0

你可以把旋转要实现什么样的代码? –

回答

0

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

+0

感谢Simon,这部分工作 - 问题是,当imageView旋转时,包含视图不会增长以反映图像视图的新框架,从而产生裁剪的截图。我觉得在这里很愚蠢,因为我似乎无法使包含视图匹配旋转的imageView的尺寸。我已经尝试设置包含视图的边界和帧属性动态imageview旋转 - 但没有喜悦......? –

+0

我尝试通过使用self.view,仍然没有喜悦的变焦视图放大http://stackoverflow.com/questions/15574845/how-do-i-take-a-screenshot-of-a-view-which-我已经有了改变 – quantumpotato

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

我假设你通过UIImage方法旋转图像。问题在于它并不是真的在旋转图像本身,它只是告诉谁来绘制图像。

我建议你只是实际使用核芯显卡旋转图像,然后你可以保存结果的方式