微信版本 7.0.10
手机小米 9


GlideUtils.getUrlBitmap(context, imgUrl, new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady([@NonNull](/user/NonNull) Bitmap resource, [@Nullable](/user/Nullable) Transition<? super Bitmap> transition) {
WXWebpageObject webpage = new WXWebpageObject();
webpage.webpageUrl = url;
WXMediaMessage msg = new WXMediaMessage(webpage);
msg.description = description;
msg.title = title;
msg.thumbData = bmpToByteArray(resource, 32);
LogUtils.d("msg.thumbData" + Arrays.toString(msg.thumbData));
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = scene;
wxApi.sendReq(req);
}
});
public static byte[] bmpToByteArray(Bitmap bmp, int imgSize) {
int quality = 95;
while (true) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, quality, baos);
byte[] bytes1 = baos.toByteArray();
LogUtil.d("aaaaa" + (bytes1.length / 1024));
if (bytes1.length / 1024 <= imgSize) {
return bytes1;
} else {
quality = quality - 5;
}
}
}