TZImageManager.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // TZImageManager.h
  3. // TZImagePickerController
  4. //
  5. // Created by 谭真 on 16/1/4.
  6. // Copyright © 2016年 谭真. All rights reserved.
  7. // 图片资源获取管理类
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. #import <AVFoundation/AVFoundation.h>
  11. #import <Photos/Photos.h>
  12. #import "TZAssetModel.h"
  13. @class TZAlbumModel,TZAssetModel;
  14. @protocol TZImagePickerControllerDelegate;
  15. @interface TZImageManager : NSObject
  16. @property (nonatomic, strong) PHCachingImageManager *cachingImageManager;
  17. + (instancetype)manager NS_SWIFT_NAME(default());
  18. + (void)deallocManager;
  19. @property (weak, nonatomic) id<TZImagePickerControllerDelegate> pickerDelegate;
  20. @property (nonatomic, assign) BOOL shouldFixOrientation;
  21. @property (nonatomic, assign) BOOL isPreviewNetworkImage;
  22. /// Default is 600px / 默认600像素宽
  23. @property (nonatomic, assign) CGFloat photoPreviewMaxWidth;
  24. /// The pixel width of output image, Default is 828px / 导出图片的宽度,默认828像素宽
  25. @property (nonatomic, assign) CGFloat photoWidth;
  26. /// Default is 4, Use in photos collectionView in TZPhotoPickerController
  27. /// 默认4列, TZPhotoPickerController中的照片collectionView
  28. @property (nonatomic, assign) NSInteger columnNumber;
  29. /// Sort photos ascending by modificationDate,Default is YES
  30. /// 对照片排序,按修改时间升序,默认是YES。如果设置为NO,最新的照片会显示在最前面,内部的拍照按钮会排在第一个
  31. @property (nonatomic, assign) BOOL sortAscendingByModificationDate;
  32. /// Minimum selectable photo width, Default is 0
  33. /// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中
  34. @property (nonatomic, assign) NSInteger minPhotoWidthSelectable;
  35. @property (nonatomic, assign) NSInteger minPhotoHeightSelectable;
  36. @property (nonatomic, assign) BOOL hideWhenCanNotSelect;
  37. /// Return YES if Authorized 返回YES如果得到了授权
  38. - (BOOL)authorizationStatusAuthorized;
  39. - (void)requestAuthorizationWithCompletion:(void (^)(void))completion;
  40. /// Get Album 获得相册/相册数组
  41. - (void)getCameraRollAlbum:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage needFetchAssets:(BOOL)needFetchAssets completion:(void (^)(TZAlbumModel *model))completion;
  42. - (void)getAllAlbums:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage needFetchAssets:(BOOL)needFetchAssets completion:(void (^)(NSArray<TZAlbumModel *> *models))completion;
  43. /// Get Assets 获得Asset数组
  44. - (void)getAssetsFromFetchResult:(PHFetchResult *)result completion:(void (^)(NSArray<TZAssetModel *> *models))completion;
  45. - (void)getAssetsFromFetchResult:(PHFetchResult *)result allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(NSArray<TZAssetModel *> *models))completion;
  46. - (void)getAssetFromFetchResult:(PHFetchResult *)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(TZAssetModel *model))completion;
  47. /// Get photo 获得照片
  48. - (PHImageRequestID)getPostImageWithAlbumModel:(TZAlbumModel *)model completion:(void (^)(UIImage *postImage))completion;
  49. - (PHImageRequestID)getPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
  50. - (PHImageRequestID)getPhotoWithAsset:(PHAsset *)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
  51. - (PHImageRequestID)getPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
  52. - (PHImageRequestID)getPhotoWithAsset:(PHAsset *)asset photoWidth:(CGFloat)photoWidth completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler networkAccessAllowed:(BOOL)networkAccessAllowed;
  53. - (PHImageRequestID)requestImageDataForAsset:(PHAsset *)asset completion:(void (^)(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler;
  54. /// Get full Image 获取原图
  55. /// 如下两个方法completion一般会调多次,一般会先返回缩略图,再返回原图(详见方法内部使用的系统API的说明),如果info[PHImageResultIsDegradedKey] 为 YES,则表明当前返回的是缩略图,否则是原图。
  56. /// 以下3个方法取的都是原图,如果像素很高,可能出现爆内存的情况,默认大小为:PHImageManagerMaximumSize,默认缩放方式:PHImageContentModeAspectFit
  57. - (PHImageRequestID)getOriginalPhotoWithAsset:(PHAsset *)asset completion:(void (^)(UIImage *photo,NSDictionary *info))completion;
  58. - (PHImageRequestID)getOriginalPhotoWithAsset:(PHAsset *)asset newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
  59. - (PHImageRequestID)getOriginalPhotoWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
  60. /// 这个方法会对获取到的图片按给定的大小进行等比例缩放
  61. - (PHImageRequestID)getOriginalPhotoWithAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)mode progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler newCompletion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion;
  62. // 该方法中,completion只会走一次
  63. - (PHImageRequestID)getOriginalPhotoDataWithAsset:(PHAsset *)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
  64. - (PHImageRequestID)getOriginalPhotoDataWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion;
  65. /// Save photo 保存照片
  66. - (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(PHAsset *asset, NSError *error))completion;
  67. - (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion;
  68. /// Save video 保存视频
  69. - (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(PHAsset *asset, NSError *error))completion;
  70. - (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(PHAsset *asset, NSError *error))completion;
  71. /// Get video 获得视频
  72. - (void)getVideoWithAsset:(PHAsset *)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion;
  73. - (void)getVideoWithAsset:(PHAsset *)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *, NSDictionary *))completion;
  74. - (void)requestVideoWithAsset:(PHAsset *)asset
  75. startHandler:(void (^)(PHImageRequestID))startHandler
  76. progressHandler:(void (^)(double progress, NSError *error, BOOL *stop))progressHandler
  77. completion:(void (^)(AVAsset *))completion;
  78. /// Export video 导出视频 presetName: 预设名字,默认值是AVAssetExportPreset640x480
  79. - (void)getVideoOutputPathWithAsset:(PHAsset *)asset success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure;
  80. - (void)getVideoOutputPathWithAsset:(PHAsset *)asset presetName:(NSString *)presetName success:(void (^)(NSString *outputPath))success failure:(void (^)(NSString *errorMessage, NSError *error))failure;
  81. /// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
  82. - (void)getVideoOutputPathWithAsset:(PHAsset *)asset completion:(void (^)(NSString *outputPath))completion __attribute__((deprecated("Use -getVideoOutputPathWithAsset:failure:success:")));
  83. /// Get photo bytes 获得一组照片的大小
  84. - (void)getPhotosBytesWithArray:(NSArray *)photos completion:(void (^)(NSString *totalBytes))completion;
  85. - (BOOL)isCameraRollAlbum:(PHAssetCollection *)metadata;
  86. /// 检查照片大小是否满足最小要求
  87. - (BOOL)isPhotoSelectableWithAsset:(PHAsset *)asset;
  88. /// 修正图片转向
  89. - (UIImage *)fixOrientation:(UIImage *)aImage;
  90. /// 获取asset的资源类型
  91. - (TZAssetModelMediaType)getAssetType:(PHAsset *)asset;
  92. /// 缩放图片至新尺寸
  93. - (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size;
  94. /// 判断asset是否是视频
  95. - (BOOL)isVideo:(PHAsset *)asset;
  96. /// for TZImagePreviewController
  97. - (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration;
  98. - (TZAssetModel *)createModelWithAsset:(PHAsset *)asset;
  99. @end
  100. //@interface TZSortDescriptor : NSSortDescriptor
  101. //
  102. //@end