简体   繁体   English

拍摄快照并保存到相机胶卷时的iOS图像大小

[英]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.

相关问题 iOS尝试将图像保存到相机胶卷但未成功 - iOS attempting to save image to camera roll but not succeeding 使用UIImageWriteToSavedPhotosAlbum将图像保存到相机胶卷 - Save image to camera roll with UIImageWriteToSavedPhotosAlbum 如何将图像保存到相机胶卷? - How can I save an image to the camera roll? 在相机胶卷中保存图像并获取资产网址 - save image in camera roll and get asset url 如何将png图像保存到相机胶卷中? - How to save a png image to camera roll? 将UIImagePickerController与源类型camera一起使用时,是否必须将捕获的图像保存到Camera Roll? - Must I save the captured image to the Camera Roll when using UIImagePickerController with source type camera? 在iOS中从相机胶卷获取特定图像 - Fetching specific image from Camera roll in iOS 将iPhone相机中的图像直接保存到文档文件夹而不是相机胶卷? - Save image from iPhone camera directly to documents folder and not to camera roll? iOS5 Twitter Framework-从相机/相机胶卷中选择图像 - iOS5 Twitter Framework - Selecting an image from camera / camera roll 通过writeImageToSavedPhotosAlbum:metadata:completionBlock:保存时,可以将图像与相机胶卷一起保存到特定相册吗? - Can I save an image to a specific album with the camera roll when saving via writeImageToSavedPhotosAlbum:metadata:completionBlock:?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM