繁体   English   中英

将UIView渲染为大于屏幕上的UIImage

[英]Render a UIView to a UIImage larger than it is on screen

我想将UIView渲染为UIImage。 但是,我想将其渲染得比在屏幕上大得多,并且没有像素化。

目前我正在使用...

UIGraphicsBeginImageContextWithOptions(size, YES, 0.0);
[self.pageViewController.view.layer renderInContext:context];
renderedViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

我努力了...

self.pageViewController.view.transform = CGAffineTransformMakeScale(4.0f, 4.0f);

这会更改视图的大小,但是在缩放视图之前会呈现原始大小。

我也尝试过...

CGContextScaleCTM(UIGraphicsGetCurrentContext(), 4.0, 4.0);

但这只会放大低分辨率图像,从而导致质量较差的结果。

设置...

UIView contentScaleFactor

也没有帮助我将UIView渲染得更大。

试试看,如果设备支持视网膜,您将获得2倍大小的视图图像

  - (UIImage *)imageOfView:(UIView *)view
{

    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 0.0);
    } else {
        UIGraphicsBeginImageContext(view.bounds.size);
    }

    [view.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return img;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM