我可以UIView
使用以下代码从 iPhone 6 截取屏幕截图:-
在这里,我打印了 2 个日志。首先给我图像大小{375, 667}
,但在将其转换为 PNG 格式后,它给了我图像大小{750, 1334}
。
我知道它正在将其转换为视网膜显示。每个点在屏幕上由 2 个像素表示,因此保存的图像是分辨率的两倍。
但我需要{375, 667}
PNG格式的图像大小。
- (UIImage *)imageWithView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"Image Size: %@", image); // Image Size: <UIImage: 0x1700880c0>, {375, 667}
NSData* imageData = UIImagePNGRepresentation(image);
UIImage* pngImage = [UIImage imageWithData:imageData];
UIImageWriteToSavedPhotosAlbum(pngImage, nil, nil, nil);
NSLog(@"PNG Image Size: %@", pngImage); // PNG Image Size: <UIImage: 0x174087760>, {750, 1334}
return image;
}
小图:-