拍摄的屏幕与转型

时间:2011-12-05 06:36:36

标签: iphone ios4

我试图拍摄具有2到3次视图的ipad屏幕快照。 我能够做到这一点。

现在我的问题是当我处于横向模式时,我只是用

转换一个视图
CGAffineTransform transform;
transform = CGAffineTransformMakeRotation(M_PI/2);
imgPlayBoard.transform = transform;

现在,当我拍摄快照时,图像视图中的图像显示为纵向。 发生了什么我无法得到它。我正在使用以下功能拍摄快照。

-(UIImage *)saveImage{

UIGraphicsBeginImageContext(imgPlayBoard.frame.size); 
[imgPlayBoard.layer renderInContext:UIGraphicsGetCurrentContext()];
[imagesView.layer renderInContext:UIGraphicsGetCurrentContext()];
[drawBoard.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIImageWriteToSavedPhotosAlbum(resultingImage, nil, nil, nil);
UIGraphicsEndImageContext();
return resultingImage;
}

这就是我得到的形象。快照中图像的大小相同,但所有的图像都是白色的。

1 个答案:

答案 0 :(得分:3)

确定.. 我自己找到了解决方案。 一切都很好。但是,由于我正在转换图像视图,然后将其渲染到上下文,因此它将图像视图的原始图像丢弃转换。所以我所做的就是我想在图像中看到的所有三个视图,我将它们添加到UIView中,然后拍摄了该视图。 这解决了我的问题。 :) 所以现在我的功能如下所示

-(UIImage *)saveImage{
    UIGraphicsBeginImageContext(imgPlayBoard.frame.size); 
    [containerView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext();
    return resultingImage;
}