EMImageMessageBody.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /**
  2. * \~chinese
  3. * @header EMImageMessageBody.h
  4. * @abstract 图片消息体类
  5. * @author Hyphenate
  6. * @version 3.00
  7. *
  8. * \~english
  9. * @header EMImageMessageBody.h
  10. * @abstract Image message body class
  11. * @author Hyphenate
  12. * @version 3.00
  13. */
  14. #import <Foundation/Foundation.h>
  15. #import "EMFileMessageBody.h"
  16. /**
  17. * \~chinese
  18. * 创建的图片消息体。以下为两种图片消息体生成的方式,图片数据和图片显示名称或者图片内容和缩略图数据。
  19. * -(instancetype)initWithData:displayName:
  20. * or
  21. * -(instancetype)initWithData:thumbnailData:
  22. * Note: 图片消息体,SDK 会根据压缩率 compressRatio 來发送消息。
  23. *
  24. * \~english
  25. * The image message body.
  26. *
  27. * You can create an image message body by calling one of the following methods:
  28. *
  29. * -`(instancetype)initWithData:displayName:`
  30. * -`(instancetype)initWithData:thumbnailData:`
  31. *
  32. * Note: SDK will compress the image based on the attribute compressRatio when delivering the image.
  33. */
  34. @interface EMImageMessageBody : EMFileMessageBody
  35. /**
  36. * \~chinese
  37. * 图片附件的尺寸。
  38. *
  39. * \~english
  40. * The resolution of the image.
  41. */
  42. @property (nonatomic) CGSize size;
  43. /**
  44. * \~chinese
  45. * 图片消息文件的压缩率。
  46. *
  47. * SDK 在发送图片消息时,会根据该参数的值来压缩图片文件。取值范围是 (0.0,1.0],默认值是 0.6。其中 1.0 表示原图文件不压缩,0.6 表示将原图文件大小压缩为初始文件的 0.6 倍。如果设置小于等于 0,则 SDK 使用默认值。
  48. *
  49. * \~english
  50. * The compression ratio of the image file.
  51. *
  52. * When sending the image message, the SDK compresses the image file according to the value of this parameter. The value range is (0.0, 1.0], and the default value is 0.6. 1.0 means that the SDK does not compress the image file, and 0.6 means that the SDK compresses the file size to 60% of the original. If you set this parameter to a value lower than 0 (included), the SDK uses the default value.
  53. */
  54. @property (nonatomic) CGFloat compressionRatio;
  55. /**
  56. * \~chinese
  57. * 缩略图的显示名。
  58. *
  59. * \~english
  60. * The display name of thumbnail.
  61. */
  62. @property (nonatomic, copy) NSString *thumbnailDisplayName;
  63. /**
  64. * \~chinese
  65. * 缩略图的本地路径。发送方可以根据该属性获取缩略本地路径。调用 imageWithContentsOfFile 方法,传入 thumbnailLocalPath 即可获取缩略图的数据。
  66. *
  67. * UIImage *image = [UIImage imageWithContentsOfFile:thumbnailLocalPath];
  68. *
  69. * \~english
  70. * The local path of the thumbnail.
  71. * UIImage *image = [UIImage imageWithContentsOfFile:thumbnailLocalPath];
  72. */
  73. @property (nonatomic, copy) NSString *thumbnailLocalPath;
  74. /**
  75. * \~chinese
  76. * 缩略图在服务器的路径。接收方可以通过该属性获取缩略图服务器路径。
  77. *
  78. * \~english
  79. * The URL path of the thumbnail of the server.
  80. *
  81. * The message receiver gets the thumbnail with this member.
  82. */
  83. @property (nonatomic, copy) NSString *thumbnailRemotePath;
  84. /**
  85. * \~chinese
  86. * 缩略图的密钥。下载缩略图时用户需要提供密钥进行校验。
  87. *
  88. * \~english
  89. * The secret key for the thumbnail. A key is required for verification when downloading thumbnail.
  90. */
  91. @property (nonatomic, copy) NSString *thumbnailSecretKey;
  92. /**
  93. * \~chinese
  94. * 缩略图的尺寸。
  95. *
  96. * \~english
  97. * The resolution of the thumbnail file.
  98. */
  99. @property (nonatomic) CGSize thumbnailSize;
  100. /**
  101. * \~chinese
  102. * 缩略图文件的大小, 以字节为单位。
  103. *
  104. * \~english
  105. * The data length (bytes) of the thumbnail file.
  106. */
  107. @property (nonatomic) long long thumbnailFileLength;
  108. /**
  109. * \~chinese
  110. * 缩略图下载状态。
  111. *
  112. * \~english
  113. * The download status of the thumbnail.
  114. */
  115. @property (nonatomic)EMDownloadStatus thumbnailDownloadStatus;
  116. /**
  117. * \~chinese
  118. * 初始化图片消息体。
  119. *
  120. * @param aData 图片数据。如果该图片的分辨率和你在控制台 Thumbnail Size 中配置的 width 和 height 不一致,SDK 会对该图片进行压缩。压缩原则维持图片的宽高比,是在控制台 width 和 height 的值为缩略图宽高中的更大值,然后按宽高比计算另一个值。以控制台中配置的 width 和 height 为 200 x 200 为例:
  121. *
  122. * 如果 aData 的分辨率为 200 x 400 (1:2),则生成的缩略图分辨率为 100 x 200。
  123. * 如果 aData 的分辨率为 600 x 300 (2:1),则生成的缩略图分辨率为 200 x 100。
  124. *
  125. * @param aThumbnailData 缩略图数据。该参数不会上传到服务器,只用于本地展示。
  126. *
  127. * @Result 图片消息体实例。
  128. *
  129. * \~english
  130. * Initializes an image message body instance.
  131. *
  132. * The image receiver will receive object thumbnail that generated based on sender's aData object.
  133. *
  134. * Adjusts thumbnail resolution on Hyphenate console -> "Thumbnail Size" -> width and height. Unit in px.
  135. * ex. aData resolution 200 x 400 (1:2), thumbnail resolution setting (width x height) 200 x 200, then will generate thumbnail in 100 x 200
  136. * ex. aData resolution 600 x 300 (2:1), thumbnail resolution setting (width x height) 200 x 200, then will generate thumbnail in 200 x 100
  137. *
  138. * The image sender can obtain thumbnail from thumbnailLocalPath.
  139. *
  140. * The image receiver will get thumbnail stored under thumbnailRemotePath after a successful download automatically.
  141. * However, if the automatic downloading failed, use the following method,
  142. * downloadMessageThumbnail:progress:completion:
  143. *
  144. * @param aData The original image object in NSData format.
  145. * @param aThumbnailData The thumbnail in NSData format. Will not push to server, but only for local usage.
  146. *
  147. * @result An image message body instance.
  148. */
  149. - (instancetype)initWithData:(NSData *)aData
  150. thumbnailData:(NSData *)aThumbnailData;
  151. @end