我正在尝试拍摄有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;
}这就是我得到的图像。图像的大小在快照中是相同的,但所有的尾巴都是白色的。
发布于 2011-12-05 16:28:28
好的..。我自己找到了解决方案。一切都运行得很好。但是,由于我要转换图像视图,然后将其呈现到上下文中,所以它采用了图像视图的原始图像,而放弃了转换。所以我所做的就是在一张图片中添加我想要的所有三个视图,我将它们添加到一个uiview中,然后对该UIView进行快照。这解决了我的问题。:)所以现在我的函数显示如下
-(UIImage *)saveImage{
UIGraphicsBeginImageContext(imgPlayBoard.frame.size);
[containerView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultingImage;
}https://stackoverflow.com/questions/8381788
复制相似问题