android 微信分享多张图片大小,Android 关于微信分享图片过大失败的解决方案

android 关于微信分享图片过大失败的解决方案。这是因为微信对缩略图做了限制,最大不超过32k。

所以可以先通过图片加载工具获取bitmap,然后进行压缩,压缩方法如下:

//压缩图片

public bitmap createbitmapthumbnail(bitmap bitmap) {

int width = bitmap.getwidth();

int height = bitmap.getheight();

// 设置想要的大小

int newwidth = 99;

int newheight = 99;

// 计算缩放比例

float scalewidth = ((float) newwidth) / width;

float scaleheight = ((float) newheight) / height;

// 取得想要缩放的matrix参数

matrix matrix = new matrix();

matrix.postscale(scalewidth, scaleheight);

// 得到新的图片

bitmap newbitmap = bitmap.createbitmap(bitmap, 0, 0, width, height, matrix, true);

return newbitmap;

}

然后封装成umusic对象进行音频分享:

final umusic music = new umusic(detail.path);//音频媒体对象

umimage umimage = new umimage(mactivity, bitmap);//将缩略图封装成umimage对象,在设置给音频媒体对象

music.settitle(detail.name);

music.setthumb(umimage);

new shareaction(mactivity).setplatform(media).setcallback(umsharelistener)//设置回调

.withtitle(detail.name)//标题

.withtext(getstring(r.string.share_text_pre) + detail.name + getstring(r.string.share_text_next))//描述信息

.withmedia(umusic)//媒体对象

.withtargeturl(url)//目标地址,就是点击分享要跳转的页面

.share();

分享视频:

string url = postsharecontent(mainurl, detail);//url点击跳转页面地址

umvideo image = new umvideo(url);

image.settitle(detail.name);

image.setthumb(detail.coverpath);//这里如果图片过大也应该和音频一样,

log.log = false;

new shareaction(mactivity).setplatform(media).setcallback(umsharelistener)

.withtitle(detail.name)

.withtext(getstring(r.string.share_text_pre) + detail.name + getstring(r.string.share_text_next))

.withmedia(image)

// .withtargeturl(url)//地址封装在umvideo中,所以不必调用此方法

.share();

loggerutils.d(tag + "\n" + string.format(" 分享地址 :%s \n 分享标题 :%s \n 分享图标 :%s \n 分享音频 :%s",

url,detail.name,detail.coverpath,detail.path));

分享图片:

umimage image = new umimage(mactivity, detail.path);

image.settitle(detail.name);

image.setthumb(detail.coverpath);

string url = postsharecontent(mainurl, detail);

log.log = false;

// config.istoasttip = true;

new shareaction(mactivity).setplatform(media).setcallback(umsharelistener)

.withtitle(detail.name)

.withtext(getstring(r.string.share_text_pre) + detail.name + getstring(r.string.share_text_next))

.withmedia(image)

.withtargeturl(url)

.share();

最后接口回调类:

/**

* 分享回调监听

*/

private umsharelistener umsharelistener = new umsharelistener() {

@override

public void onresult(share_media platform) {

loggerutils.d("share result");

}

@override

public void onerror(share_media platform, throwable t) {

if (t != null) {

loggerutils.d(t.getmessage());

}

}

@override

public void oncancel(share_media platform) {

loggerutils.d("share cancel");

}

};

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值