下面的代码似乎可以很好地从视网膜分辨率的 View 中渲染图像。问题是当我的设备处于横向时它似乎不起作用。它返回旋转 90 度的图像。
我是否需要添加图像或上下文方向的选项?
CGSize panelRect = CGSizeMake(selectedPanelView.frame.size.width, selectedPanelView.frame.size.height);
UIGraphicsBeginImageContextWithOptions(panelRect, 1, 2);
[[selectedPanelView layer] renderInContext:UIGraphicsGetCurrentContext()];
renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
最佳答案
问题似乎可以通过使用:UIImage imageWithCGImage:scale:orientation:
解决,如下所示。
UIImage *renderedImageWithOrientation = [UIImage imageWithCGImage:renderedImage.CGImage scale:1 orientation:0];
我在渲染图像后运行它,然后将图像添加到 imageView。
关于上下文中的 iOS 渲染图像在横向方向上无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15997241/