UIImage+MultiFormat.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. @return The encoded data. If can't encode, return nil
  40. */
  41. - (nullable NSData *)sd_imageData;
  42. /**
  43. Encode the current image to data with the specify image format
  44. @param imageFormat The specify image format
  45. @return The encoded data. If can't encode, return nil
  46. */
  47. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat NS_SWIFT_NAME(sd_imageData(as:));
  48. /**
  49. Encode the current image to data with the specify image format and compression quality
  50. @param imageFormat The specify image format
  51. @param compressionQuality The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.
  52. @return The encoded data. If can't encode, return nil
  53. */
  54. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat compressionQuality:(double)compressionQuality NS_SWIFT_NAME(sd_imageData(as:compressionQuality:));
  55. /**
  56. Encode the current image to data with the specify image format and compression quality, allow specify animate/static control
  57. @param imageFormat The specify image format
  58. @param compressionQuality The quality of the resulting image data. Value between 0.0-1.0. Some coders may not support compression quality.
  59. @param firstFrameOnly Even if the image is animated image, encode the first frame only as static image.
  60. @return The encoded data. If can't encode, return nil
  61. */
  62. - (nullable NSData *)sd_imageDataAsFormat:(SDImageFormat)imageFormat compressionQuality:(double)compressionQuality firstFrameOnly:(BOOL)firstFrameOnly NS_SWIFT_NAME(sd_imageData(as:compressionQuality:firstFrameOnly:));
  63. @end