转载---CGImageSource对图像数据读取任务的抽象

本文详细介绍了如何使用CGImageSource来读取图像数据,并提供了获取图像、创建缩略图、获取图像属性及理解图像旋转方向的方法。通过与UIImageOrientation的映射关系,帮助开发者轻松处理图像旋转问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载地址:http://www.tanhao.me/pieces/1019.html

CGImageSource是对图像数据读取任务的抽象,通过它可以获得图像对象、缩略图、图像的属性(包括Exif信息)。

1.创建CGImageSourceRef

2.获取图像

3.创建图像的缩略图

4.获取图像的属性信息

其中获取到的kCGImagePropertyPixelHeight和kCGImagePropertyPixelHeight的数值是原始的值,也就是旋转之前的数值,所以要获取到显示图像的宽和高,需要对应kCGImagePropertyOrientation的值,而通过查看kCGImagePropertyOrientation的文档介绍,值分别从1-8,但其解释却让人看不懂,经过测试,得出与UIImageOrientation有以下的映射关系:

UIImageOrientationUp:             1      正常方向(默认值)   如图:UIImageOrientationUp

UIImageOrientationDown:           3       旋转180度(朝左朝右当然是一样的)    如图:UIImageOrientationDown

UIImageOrientationLeft:           8      向左逆时针旋转90度    如图:UIImageOrientationLeft

UIImageOrientationRight:          6      向右顺时针旋转90度    如图:UIImageOrientationRight

UIImageOrientationUpMirrored:     2      将原图水平的翻转到背面    如图:UIImageOrientationUpMirrored

UIImageOrientationDownMirrored:   4      在水平翻转之后再旋转180度    如图:UIImageOrientationDownMirrored

UIImageOrientationLeftMirrored:   5      在水平翻转之后向左逆时针旋转90度    如图:UIImageOrientationLeftMirrored

UIImageOrientationRightMirrored:  7      在水平翻译之后向右顺时针旋转90度    如图:UIImageOrientationRightMirrored

 

相关的Demo:头像裁剪选择器McAvatarView

转载于:https://www.cnblogs.com/yunis/p/4290774.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值