iOS Create an CGImageSource
来源:互联网 发布:杭州龙席网络盈店通 编辑:程序博客网 时间:2024/05/15 07:39
Image I/O 是 iOS SDK 提供的一个图片编解码器,支持 JPEG, JPEG2000, RAW, TIFF, BMP, GIF, and PNG ,支持 metadata 读取,提供颜色管理。
CGImageSource :数据读取的接口,支持 URL, CFData, or data consumer 。提供读取 CGImage, Thumbnail CGImage, image properties 等等。
CGImageDestination:数据写入的接口,支持 URL, CFData, or data consumer 。可写入单个或多个 CGImage, 包括 Thumbnail CGImage, image properties
一、Image I/O 读取 ALAssets Library 图片数据
ALAssets Library
ALAssetsLibrary : 提供访问 Photos App 下的图片与视频的功能。
ALAssetsGroup :表示一个有序的 ALAsset 的集合分组。
ALAsset :表示 Photos 中的一项图片与视频。
ALAssetRepresentation :表示 ALAsset 中的一种展示。
1. 实例一个 ALAssetsLibrary :
ALAssetsLibrary _assetsLibrary = [[ALAssetsLibrary alloc] init];
2. 遍历 ALAssetsGroup :
[_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {} failureBlock:^(NSError *error){} ];
3. 遍历 ALAsset :
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {}];
4. 读取 NSData :
ALAssetRepresentation *representation = result.defaultRepresentation;
CGImageRef cImage = [representation fullScreenImage];
uint8_t *buffer = (uint8_t *)malloc(representation.size);
NSError *error;
NSUInteger length = [representation getBytes:buffer fromOffset:0 length:representation.size error:&error];
NSData *data = [NSData dataWithBytes:buffer length:length];
5. 构造 CGImageSource :
CGImageSourceRef cImageSource = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
二、Image I/O 从 NSBundle 读取图片数据
1.URL 直接生成 CGImageSource
NSString *imagePath =[[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"];
CGImageSourceRef cImageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:imagePath], NULL);
三、 Image I/O 从 UIImage 读取图片数据
1. UIImageJPEGRepresentation/UIImagePNGRepresentation/CGImageGetDataProvider
NSData *UIImageJPEGRepresentation(UIImage *image, CGFloat compressionQuality);
NSData *UIImagePNGRepresentation(UIImage *image);
CGImageSourceRef cImageSource = CGImageSourceCreateWithData(data);
CGDataProvider cDataProvider = CGImageGetDataProvider(cImage);
CGImageSourceRef cImageSource = CGImageSourceCreateWithDataProvider(cDataProvider);
- iOS Create an CGImageSource
- iOS Create an CGImageSource
- CGImageSource
- Create an iOS Universal Framework
- CGImageSource Reference
- Create an error!
- create an external table
- Create an Inventory Organization
- --Create an class.
- create an outside distribution
- iOS Create
- Create an account in Mysql
- F# create an XML document
- CGImageSource的用法
- iOS- Please sign in with an app-specific password. You can create one at applied.apple.com.
- Unable to create an ArcMap Service
- Create,register,and mount an ACFS filesystem.
- How to create an SMTP Trace Listener
- ZOJ-2892
- 1005. Spell It Right (20)
- Cracking the coding interview--Q2.2
- Fragment不能再构造方法中调用getActivity()
- ThinkPHP 原生SQL查询
- iOS Create an CGImageSource
- Python学习系列六:函数的参数对应
- IOS中系统唯一标识ID
- block代码块
- android通过反射代替R来获取控件对象
- jxl读取excel
- CodeForces 337C Captains Mode(dp+位运算+贪心)
- 11572 - Unique Snowflakes(two pointer)
- LeetCode OJ:Wildcard Matching