FBImageIOScaler.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <Foundation/Foundation.h>
  10. #import <CoreGraphics/CoreGraphics.h>
  11. @class UTType;
  12. NS_ASSUME_NONNULL_BEGIN
  13. // Those values define the allowed ranges for the scaling factor and compression quality settings
  14. extern const CGFloat FBMinScalingFactor;
  15. extern const CGFloat FBMaxScalingFactor;
  16. extern const CGFloat FBMinCompressionQuality;
  17. extern const CGFloat FBMaxCompressionQuality;
  18. @interface FBImageIOScaler : NSObject
  19. /**
  20. Puts the passed image on the queue and dispatches a scaling operation. If there is already a image on the
  21. queue it will be replaced with the new one
  22. @param image The image to scale down
  23. @param completionHandler called after successfully scaling down an image
  24. @param scalingFactor the scaling factor in range 0.01..1.0. A value of 1.0 won't perform scaling at all
  25. @param compressionQuality the compression quality in range 0.0..1.0 (0.0 for max. compression and 1.0 for lossless compression)
  26. Only applicable for UTTypeJPEG
  27. */
  28. - (void)submitImage:(NSData *)image
  29. scalingFactor:(CGFloat)scalingFactor
  30. compressionQuality:(CGFloat)compressionQuality
  31. completionHandler:(void (^)(NSData *))completionHandler;
  32. /**
  33. Scales and crops the source image
  34. @param image The source image data
  35. @param uti Either UTTypePNG or UTTypeJPEG
  36. @param rect The cropping rectange for the screenshot. The value is expected to be non-scaled one
  37. since it happens after scaling/orientation change.
  38. CGRectNull could be used to take a screenshot of the full screen.
  39. @param scalingFactor Scaling factor in range 0.01..1.0. A value of 1.0 won't perform scaling at all
  40. @param compressionQuality the compression quality in range 0.0..1.0 (0.0 for max. compression and 1.0 for lossless compression).
  41. Only works if UTI is set to kUTTypeJPEG
  42. @param error The actual error instance if the returned result is nil
  43. @returns Processed image data compressed according to the given UTI or nil in case of a failure
  44. */
  45. - (nullable NSData *)scaledImageWithImage:(NSData *)image
  46. uti:(UTType *)uti
  47. rect:(CGRect)rect
  48. scalingFactor:(CGFloat)scalingFactor
  49. compressionQuality:(CGFloat)compressionQuality
  50. error:(NSError **)error;
  51. @end
  52. NS_ASSUME_NONNULL_END