您的位置:首页 > 移动开发 > 微信开发

微信分享 微信对图片文字大小的限制 代码如下

2016-11-03 15:10 691 查看
微信分享 微信对缩略图 文字大小的限制 代码如下

final boolean checkArgs() {
if ((getType() == 8)
&& (((this.thumbData == null) || (this.thumbData.length == 0)))) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, thumbData should not be null when send emoji");
return false;
}
if ((this.thumbData != null) && (this.thumbData.length > 32768)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, thumbData is invalid");
return false;
}
if ((this.title != null) && (this.title.length() > 512)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, title is invalid");
return false;
}
if ((this.description != null) && (this.description.length() > 1024)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, description is invalid");
return false;
}
if (this.mediaObject == null) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, mediaObject is null");
return false;
}
if ((this.mediaTagName != null) && (this.mediaTagName.length() > 64)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, mediaTagName is too long");
return false;
}
if ((this.messageAction != null)
&& (this.messageAction.length() > 2048)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, messageAction is too long");
return false;
}
if ((this.messageExt != null) && (this.messageExt.length() > 2048)) {
a.a("MicroMsg.SDK.WXMediaMessage",
"checkArgs fail, messageExt is too long");
return false;
}
return this.mediaObject.checkArgs();
}


注:

1,图片的缩略图不能超过32k 不然会报错

2, 有的图片明明没有超过规定大小却依然分享失败

报checkArgs fail, thumbData is invalid错误

(微信demo 修改util类 默认是jar包里的 不过微信给了源码 修改后添加到项目里 记得删除代码里的import)

原
ByteArrayOutputStream output = new ByteArrayOutputStream();
bmp.compress(CompressFormat.PNG, 100, output);
if (needRecycle) {
bmp.recycle();
}

byte[] result = output.toByteArray();
try {
output.close();
} catch (Exception e) {
e.printStackTrace();
}

return result;
}
``


现    int i;
int j;
if (bmp.getHeight() > bmp.getWidth()) {
i = bmp.getWidth();
j = bmp.getWidth();
} else {
i = bmp.getHeight();
j = bmp.getHeight();
}
Bitmap localBitmap = Bitmap.createBitmap(i, j, Bitmap.Config.RGB_565);
Canvas localCanvas = new Canvas(localBitmap);

while (true) {
localCanvas.drawBitmap(bmp, new Rect(0, 0, i, j), new Rect(0, 0,i, j), null);
if (needRecycle)
bmp.recycle();
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
localBitmap.compress(Bitmap.CompressFormat.JPEG, 100,
localByteArrayOutputStream);
localBitmap.recycle();
byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
try {
localByteArrayOutputStream.close();
return arrayOfByte;
} catch (Exception e) {
//F.out(e);
}
i = bmp.getHeight();
j = bmp.getHeight();
}
}


“`
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: