微信分享之因分享图片太大无法起调微信客户端
来源:互联网 发布:wp8.1软件 编辑:程序博客网 时间:2024/04/30 13:18
微信分享时调用微信客户端有时会出现无法起调的问题,可能的原因是分享出去的图片大小超出了微信要求(要求不大于32KB)对于这个问题可以先压缩图片在分享上传。
- 微信分享集成指南:
https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419317332&token=&lang=zh_CN
2.图片压缩并转换成data
+ (NSData *)reSizeImageData:(UIImage *)sourceImage maxImageSize:(CGFloat)maxImageSize maxFileSizeWithKB:(CGFloat)maxFileSize{ if (maxFileSize <= 0.0) maxFileSize = 1024.0; if (maxImageSize <= 0.0) maxImageSize = 1024.0; //先调整分辨率 CGSize newSize = CGSizeMake(sourceImage.size.width, sourceImage.size.height); CGFloat tempHeight = newSize.height / maxImageSize; CGFloat tempWidth = newSize.width / maxImageSize; if (tempWidth > 1.0 && tempWidth > tempHeight) { newSize = CGSizeMake(sourceImage.size.width / tempWidth, sourceImage.size.height / tempWidth); } else if (tempHeight > 1.0 && tempWidth < tempHeight){ newSize = CGSizeMake(sourceImage.size.width / tempHeight, sourceImage.size.height / tempHeight); } UIGraphicsBeginImageContext(newSize); [sourceImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //调整大小 NSData *imageData = UIImageJPEGRepresentation(newImage,1.0); CGFloat sizeOriginKB = imageData.length / 1024.0; CGFloat resizeRate = 0.9; while (sizeOriginKB > maxFileSize && resizeRate > 0.1) { imageData = UIImageJPEGRepresentation(newImage,resizeRate); sizeOriginKB = imageData.length / 1024.0; resizeRate -= 0.1; } return imageData;}
// 把图片大小压缩到32KB以下就可以了
0 0
- 微信分享之因分享图片太大无法起调微信客户端
- 微信分享缩略图太大
- Android 分享功能之 微信 图片分享
- android之微信分享图片
- Android集成微信分享,由于分享的缩略图大于32K,而无法调起微信客户端
- 微信分享自定义图片
- 微信分享图片变黑
- 微信分享图片修改
- Android 微信分享图片!!!
- 微信分享的图片
- 微信分享网络图片
- android分享之微信分享
- Android 微信分享之图片加载失败
- iOS 分享功能之图片压缩(微信好友-朋友圈)
- pc微信客户端玩具分享
- Android之微信分享
- 使用ShareSDK无法微信分享的解决方法,sharesdk分享
- QQ,微博,微信链接分享无法显示分享记录
- sql in的参数化查询
- [代码实例][.NET]操作Excel文件
- Android Support v4、v7、v13的区别和应用场景
- 二分查找算法
- 猜数字游戏的提示 (Master-Mind Hints, UVa 340)
- 微信分享之因分享图片太大无法起调微信客户端
- 3个最好的PHP框架的Web开发
- 可新可新的新手刚刚上路,学C语言,见笑了,大神不用来了。(内有break与continue)
- Raft算法和开源实现
- Visual Studio 2015,OpenCV3.2 环境搭建记录
- Linux学习笔记-VMware Workstation 12 虚拟机搭建 CentOS 7 练习机
- 赶紧来许愿:canvas流星雨的背景
- C语言中判断文件是否存在的方法详解
- codeforces360e