存储图片到photo library与存储video到photo library的API差不多,但也有所不同。图片是可以直接把数据写入photo library,而video需要先把数据存到临时文件然后,然后通过临时文件的路径去转存到photo library。
我们直接来看相应的API:
// These methods can be used to add photos or videos to the saved photos album.
// With a UIImage, the API user can use -[UIImage CGImage] to get a CGImageRef, and cast -[UIImage imageOrientation] to ALAssetOrientation.
- (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock;
// The API user will have to specify the orientation key in the metadata dictionary to preserve the orientation of the image
- (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef metadata:(NSDictionary *)metadata completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_1);
// If there is a conflict between the metadata in the im

本文介绍了如何将图片和视频保存到iOS的PhotoLibrary。图片可以直接写入,而视频需先保存到临时文件,再通过路径导入。提供了相关API介绍及简单代码示例,包括UIImage和NSURL的使用。同时,分享了一个将工程资源视频写入PhotoLibrary的Demo,便于测试。
最低0.47元/天 解锁文章
2148

被折叠的 条评论
为什么被折叠?



