UIImage+MultiFormat.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDWebImageCompat.h"
  9. #import "NSData+ImageContentType.h"
  10. /**
  11. UIImage category for convenient image format decoding/encoding.
  12. */
  13. @interface UIImage (MultiFormat)
  14. #pragma mark - Decode
  15. /**
  16. Create and decode a image with the specify image data
  17. @param data The image data
  18. @return The created image
  19. */
  20. + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data;
  21. /**
  22. Create and decode a image with the specify image data and scale
  23. @param data The image data
  24. @param scale The image scale factor. Should be greater than or equal to 1.0.
  25. @return The created image
  26. */
  27. + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data scale:(CGFloat)scale;
  28. /**
  29. Create and decode a image with the specify image data and scale, allow specify animate/static control
  30. @param data The image data
  31. @param scale The image scale factor. Should be greater than or equal to 1.0.
  32. @param firstFrameOnly Even if the image data is animated image format, decode the first frame only as static image.
  33. @return The created image
  34. */
  35. + (nullable UIImage *)sd_imageWithData:(nullable NSData *)data scale:(CGFloat)scale firstFrameOnly:(BOOL)firstFrameOnly;
  36. #pragma mark - Encode
  37. /**
  38. Encode the current image to the data, the image format is unspecified
  39. @note If the receiver is `SDAnimatedImage`, this will return the animated image data if available. No more extra encoding process.
  40. @return The encoded data. If can't encode, return nil
  41. */
  42. - (nullable NSData *)sd_imageData;
  43. /**
  44. Encode the current image to data with the specify image format
  45. @param imageFormat The specify image format
  46. @return The encoded data. If can't encode, return nil
  47. */
  48. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat NS_SWIFT_NAME(sd_imageData(as:));
  49. /**
  50. Encode the current image to data with the specify image format and compression quality
  51. @param imageFormat The specify image format
  52. @param compressionQuality The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.
  53. @return The encoded data. If can't encode, return nil
  54. */
  55. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat compressionQuality:(double)compressionQuality NS_SWIFT_NAME(sd_imageData(as:compressionQuality:));
  56. /**
  57. Encode the current image to data with the specify image format and compression quality, allow specify animate/static control
  58. @param imageFormat The specify image format
  59. @param compressionQuality The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.
  60. @param firstFrameOnly Even if the image is animated image, encode the first frame only as static image.
  61. @return The encoded data. If can't encode, return nil
  62. */
  63. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat compressionQuality:(double)compressionQuality firstFrameOnly:(BOOL)firstFrameOnly NS_SWIFT_NAME(sd_imageData(as:compressionQuality:firstFrameOnly:));
  64. @end