0
所以,这里是我的视图层次结构:我有一个视图(默认viewControllher的_view)在一个UIWebView子视图中的Xib。在同一个Xib文件中,单独的第二个视图(不在_view内部)称为floatView。 floatView以编程方式添加到UIWebView的顶部,并可由用户拖动。内部floatView我有一个较小的子视图(cropView)。 我想使用cropView作为裁剪框架来获取它下面的可见部分webView。使用浮动UIview裁剪(UIGraphicsImageContext)图像
继承人我试图用它来做代码,但结果不是我所需要的。
- (IBAction)captureImage:(id)sender {
CGSize layerSize = self.view.bounds.size;
UIGraphicsBeginImageContext(layerSize);
[self.webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
[floatView convertRect:cropView.frame toView:self.view];
CGRect CropFrame = cropView.frame;
CGImageRef subImageRef = CGImageCreateWithImageInRect(image.CGImage, CropFrame);
UIImage *subViewImage = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(subViewImage, nil, nil, nil);
}
我在相机胶卷中得到的图像是我裁剪的图像与正确的大小不在可见的webView的正确位置。
我看了其他文章和解决方案,但找不到解决我的问题的解决方案。任何帮助,将不胜感激。
谢谢