xcode 如何拍摄高质量的截图/保存图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8901172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:01:30  来源:igfitidea点击:

How to take high quality screenshot / save image?

iphoneiosxcodeipad

提问by user339946

I'm currently using the following code to produce an image whenever the user presses "Save Image":

我目前正在使用以下代码在用户按下“保存图像”时生成图像:

    self.toolbar.hidden = YES;

    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

    self.toolbar.hidden = NO;

I'm basically hiding the elements on the screen that I don't want to show, then taking a normal screenshot and saving to the photo library. I was wondering if it was possible to save at a higher resolution or quality. Thank you

我基本上是将不想显示的元素隐藏在屏幕上,然后拍摄普通屏幕截图并保存到照片库中。我想知道是否可以以更高的分辨率或质量保存。谢谢

回答by antf

When you take a screen shot you take it with the resolution of the screen itself and not with the resolution of the items. Put differently if you have a 10 Mega Pixel image that you zoomed out to fit the screen you are no more seeing it as 10 MP, you are seeing it as screen resolution. In retina display (assuming iPhone) the screen resolution is 640*960 pixels and in normal displays it is 320*480, so every time you take a screenshot you will have this resolution not more.

当您拍摄屏幕截图时,您使用的是屏幕本身的分辨率而不是项目的分辨率。换句话说,如果您将 10 兆像素图像缩小以适应屏幕,您将不再将其视为 10 MP,而是将其视为屏幕分辨率。在 Retina 显示器(假设是 iPhone)中,屏幕分辨率是 640*960 像素,而在普通显示器中是 320*480,因此每次截屏时,您的分辨率都不会更高。