上下文中的 iOS 渲染图像在横向方向上无法按预期工作

标签 ios render cglayer uigraphicscontext

下面的代码似乎可以很好地从视网膜分辨率的 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/

相关文章:

ruby-on-rails - Rails format.xml 呈现并传递多个变量

ios - 发送带有 iPhone 应用程序链接的短信或推送通知

ios - 重叠 TableView 在其后面滚动 TableView

ios - 摆脱 UINavigationBar 右侧的空间

c - 有没有办法在同一循环中渲染我的 Termbox 游戏并处理键盘事件?

angular - Meteor 不渲染 html 模板,只渲染路径

ios - 位图 CGContext 绘图不断增加内存使用量

iphone - 如何访问 CGContext 以在屏幕外创建 CGLayer

ios - "CGLayer no longer recommended";这是普遍共识吗?

ios - 因 NSException 类型的未捕获异常而终止 Timer Swift 崩溃