Вопрос

The code below seems to work well to render an image from a view at retina resolution. The problem is it does not seem to work while my device is in landscape orientation. It returns an image rotated 90 degrees.

Do I need to add options for image or context orientation?

    CGSize panelRect = CGSizeMake(selectedPanelView.frame.size.width, selectedPanelView.frame.size.height);

    UIGraphicsBeginImageContextWithOptions(panelRect, 1, 2);

    [[selectedPanelView layer] renderInContext:UIGraphicsGetCurrentContext()];
    renderedImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
Это было полезно?

Решение

The problem seems to be fixed by using: UIImage imageWithCGImage:scale:orientation: as below.

UIImage *renderedImageWithOrientation = [UIImage imageWithCGImage:renderedImage.CGImage scale:1 orientation:0];

I run this after rendering the image, then I add the image to the imageView.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top