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

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

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();
    }
}

“`

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值