[英]iOS image size when taking snapshot and save into camera roll
I took a screenshot and saved image into camera roll, and set this image into lock screen. 我拍摄了屏幕截图并将图像保存到相机胶卷中,并将此图像设置为锁定屏幕。
but image size is 640*940 in iPhone 4. How can I make it 640*960 without any distortion? 但是在iPhone 4中,图像尺寸为640 * 940。如何将其设置为640 * 960而没有任何失真? I guess status bar has some height. 我猜状态栏有一些高度。
CGSize size = self.view.bounds.size;
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
Two ways you can go about setting the image size... 设置图像尺寸的两种方法...
Fist you can set your own frame for the screenshot: 首先,您可以为屏幕截图设置自己的框架:
CGRect rect = CGRectMake(0, 0, 640, 960);
UIView *view = [[UIView alloc]initWithFrame:rect];
UIGraphicsBeginImageContext(view.frame.size);
This will take the size you want. 这将采用您想要的尺寸。 Keep in mind that if your screen size is say 320 x 480 you will get a returned image of 640 x 960 but will be white space outside of your actual screenshot range. 请记住,如果您的屏幕尺寸为320 x 480,您将获得640 x 960的返回图像,但屏幕空白将超出您的实际屏幕截图范围。
Another approach would be to find the area you want from an object such as an image view: 另一种方法是从诸如图像视图之类的对象中找到所需的区域:
UIImageView *imageview;
UIGraphicsBeginImageContext(imageview.frame.size);
Again this will return what you want but anything outside of the actual screen size will be filled with white space. 同样,这将返回您想要的内容,但实际屏幕尺寸以外的任何内容都将填充空白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.