[ iOS ] 微信分享图片问题解决
微信分享时,图片大小必须小于32k,所以大多数情况下都需要对图片进行压缩裁剪,试过好多方法都不对,最后用如下方法成功解决问题。
// ------这种方法对图片既进行压缩,又进行裁剪 - (NSData *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize; { UIGraphicsBeginImageContext(newSize); [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return UIImageJPEGRepresentation(newImage, 0.8); } // ------调用 UIImage *img = [UIImage imageWithData:[self imageWithImage:image scaledToSize:CGSizeMake(300, 300)]]
相关推荐
戴翔的技术 2020-05-18
齐天大圣数据候 2020-05-16
过时不侯的温暖 2020-05-08
浪味仙 2020-04-20
戴翔的技术 2020-03-04
zengfanpei 2020-02-20
cbao 2020-02-14
xiaonao00 2020-01-02
xiaonao00 2019-12-25
cbao 2019-12-12
浪味仙 2019-12-10
maodouhuasheng 2019-12-04
且听真言 2019-12-01
ywwazyj 2019-11-15
badroot 2019-11-18
badroot 2019-11-17
zhichijunjun 2019-11-13
wjeymiantan 2019-11-07