CGImageSource对图像数据读取任务的抽象
来源:互联网 发布:中国联通视频软件 编辑:程序博客网 时间:2024/05/21 07:13
http://www.tanhao.me/pieces/1019.html/
CGImageSource是对图像数据读取任务的抽象,通过它可以获得图像对象、缩略图、图像的属性(包括Exif信息)。
1.创建CGImageSourceRef
12
NSString *imagePath = [[NSBundle bundleForClass:self.class] pathForImageResource:@"test.png"];CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:imagePath],NULL);
2.获取图像
1
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
3.创建图像的缩略图
12345678910111213141516171819
//缩略图的宽和高double thumbnailWidth=xxx,thumbnailHeight=xxx;//缩略图的信息的字典NSDictionary *thumbnailInfo = @{(NSString *)kCGImageSourceCreateThumbnailFromImageAlways : @YES,(NSString *)kCGImageSourceThumbnailMaxPixelSize : [NSNumber numberWithInt:MAX(thumbnailWidth,thumbnailHeight)],(NSString *)kCGImageSourceCreateThumbnailWithTransform : @YES,};//得到缩略图CGImageRef imageRef = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)thumbnailInfo );
4.获取图像的属性信息
1234567891011121314151617
CFDictionaryRef imageInfo = CGImageSourceCopyPropertiesAtIndex(imageSource, 0,NULL);//像素的宽NSNumber *pixelWidthObj = (__bridge NSNumber *)CFDictionaryGetValue(imageInfo, kCGImagePropertyPixelWidth);//像素的高NSNumber *pixelHeightObj = (__bridge NSNumber *)CFDictionaryGetValue(imageInfo, kCGImagePropertyPixelHeight);//图像的旋转方向NSInteger orientation = [(__bridge NSNumber *)CFDictionaryGetValue(imageInfo, kCGImagePropertyOrientation) integerValue];//Exif信息NSDictionary *exifInfo = (__bridge NSDictionary *)CFDictionaryGetValue(imageInfo, kCGImagePropertyExifAuxDictionary);
其中获取到的kCGImagePropertyPixelHeight和kCGImagePropertyPixelHeight的数值是原始的值,也就是旋转之前的数值,所以要获取到显示图像的宽和高,需要对应kCGImagePropertyOrientation的值,而通过查看kCGImagePropertyOrientation的文档介绍,值分别从1-8,但其解释却让人看不懂,经过测试,得出与UIImageOrientation有以下的映射关系:
UIImageOrientationUp: 1 正常方向(默认值) 如图:
UIImageOrientationDown: 3 旋转180度(朝左朝右当然是一样的) 如图:
UIImageOrientationLeft: 8 向左逆时针旋转90度 如图:
UIImageOrientationRight: 6 向右顺时针旋转90度 如图:
UIImageOrientationUpMirrored: 2 将原图水平的翻转到背面 如图:
UIImageOrientationDownMirrored: 4 在水平翻转之后再旋转180度 如图:
UIImageOrientationLeftMirrored: 5 在水平翻转之后向左逆时针旋转90度 如图:
UIImageOrientationRightMirrored: 7 在水平翻译之后向右顺时针旋转90度 如图:
- CGImageSource对图像数据读取任务的抽象
- Visual C++中实现对图像数据的读取显示
- Visual C++中实现对图像数据的读取显示
- Visual C++中实现对图像数据的读取显示
- Visual C++中实现对图像数据的读取显示
- CGImageSource的用法
- CGImageSource
- win32对jpg、gif图像的读取
- OpenCv和matlab对图像的读取
- matlab中对图像的读取
- python2.7对DICOM图像的读取
- 对树形数据的读取:
- SqlDataReader对数据的读取
- Matlab读取的图像的数据排列
- matlab读取视频文件的图像数据
- opencv-python图像数据的读取
- opencv读取图像数据的方式总结
- 读取jpeg图像数据
- java 创建两个对象
- java 对象的引用传递
- java 属性的封装和访问
- java 声明一个构造方法
- java 通过构造方法为属性赋值
- CGImageSource对图像数据读取任务的抽象
- java 构造方法的重载
- java 匿名对象的使用
- 点亮一位LED灯
- 闪烁一位LED灯
- LED流水灯
- 数码管动态显示
- 第一个CAD图
- Spark和Flume-ng的整合