拍照&相册访问相关问题

2019-02-22  本文已影响0人  lsh_01

拍照

info包含字段

allowsEditing = false时,拍照完成后用户无法调整该图片,info中字段为:

UIImagePickerControllerMediaMetadata
UIImagePickerControllerMediaType
UIImagePickerControllerOriginalImage = "<UIImage: 0x170483bb0> size {3024, 4032} orientation 3 scale 1.000000";

allowsEditing = true时,info中字段为:

UIImagePickerControllerCropRect = "NSRect: {{327, 977}, {1982, 1982}}";
UIImagePickerControllerEditedImage = "<UIImage: 0x170483700> size {750, 750} orientation 0 scale 1.000000";
UIImagePickerControllerMediaMetadata
UIImagePickerControllerMediaType
UIImagePickerControllerOriginalImage = "<UIImage: 0x170483bb0> size {3024, 4032} orientation 3 scale 1.000000";

用户调整后的图片只能是正方形,宽度为屏幕宽度方向像素数。

方向问题

拍照得到的图片,如果不处理而直接发送给服务器,可能会导致图片方向不正确;而从相册中获取的图片则不存在这种情况。

不同方向拍照后,info中字段为:

上    
UIImagePickerControllerOriginalImage = "<UIImage: 0x17029f680> size {3024, 4032} orientation 3 scale 1.000000";
UIImageOrientationRight
<UIImage: 0x174283c00> size {3024, 4032} orientation 0 scale 1.000000
左
UIImagePickerControllerOriginalImage = "<UIImage: 0x17429f400> size {4032, 3024} orientation 1 scale 1.000000";
UIImageOrientationDown
<UIImage: 0x17428cf30> size {4032, 3024} orientation 0 scale 1.000000
下
UIImagePickerControllerOriginalImage = "<UIImage: 0x1702800a0> size {3024, 4032} orientation 2 scale 1.000000";
UIImageOrientationLeft
<UIImage: 0x17029a630> size {3024, 4032} orientation 0 scale 1.000000
右
UIImagePickerControllerOriginalImage = "<UIImage: 0x1704812c0> size {4032, 3024} orientation 0 scale 1.000000";
UIImageOrientationUp
<UIImage: 0x17029a630> size {4032, 3024} orientation 0 scale 1.000000

纠正方向的代码见其他笔记。

内存控制

由于拍照得到的图片没有url,只能使用CoreGraphics进行图片压缩,建议使用绘制方式。

相册

info包含字段

UIImagePickerControllerMediaType
UIImagePickerControllerOriginalImage = "<UIImage: 0x17048d2a0> size {3024, 4032} orientation 3 scale 1.000000";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=1724BF03-E469-4470-A00C-5BBD1F863C52&ext=JPG";

内存控制

使用url可以获得assert,进而使用Photos库获取压缩后的图片,效率更高。

上一篇下一篇

猜你喜欢

热点阅读