欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

E/MicroMsg.SDK.WXMediaMessage(17582): checkArgs fail, thumbData is invalid

发布时间:2023/12/14 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 E/MicroMsg.SDK.WXMediaMessage(17582): checkArgs fail, thumbData is invalid 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

微信官网给的Demo中。图片的分享例子他是这么描述的:

String url = "http://pic2.nipic.com/20090506/1478953_125254084_2.jpg"; 
                                 
                             try
                                WXImageObject imgObj =  new WXImageObject(); 
                                imgObj.imageUrl = url; 
                                 
                                WXMediaMessage msg =  new WXMediaMessage(); 
                                msg.mediaObject = imgObj; 

                                Bitmap bmp = BitmapFactory.decodeStream( new URL(url).openStream()); 
                                Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true); 
                                bmp.recycle(); 
                                msg.thumbData = Util.bmpToByteArray(thumbBmp,  true); 
                                 
                                SendMessageToWX.Req req =  new SendMessageToWX.Req(); 
                                req.transaction = buildTransaction("img"); 
                                req.message = msg; 
                                req.scene = isTimelineCb.isChecked() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
                                api.sendReq(req); 
                                 
                                 // finish(); 
                            }  catch(Exception e) { 
                                e.printStackTrace(); 
                                Toast.makeText(SendToWXActivity.this, "Error msg"+e.toString(), 1000).show(); 
                            } 
                     
                             break
                        

 

 而在实际的使用过程中,总是报这样的一个错误,怎么也调用不到微信的分享界面。


 

05-06 10:21:35.276: E/MicroMsg.SDK.WXMediaMessage(19273): checkArgs fail, thumbData is invalid

 好像是图片处理那边出现了问题。细看这个代码。里面有一个将bitmap对象转化成byte数据字节的对象。原先的代码是这样的如下所示:

 

     public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {

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

 现将其改成如下所示的:

     public static byte[] bmpToByteArray(final Bitmap bmp, final boolean needRecycle) {

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

 

现在就可以对图片进行分享了。 有更好的解决办法,希望可以留言 !!!

总结

以上是生活随笔为你收集整理的E/MicroMsg.SDK.WXMediaMessage(17582): checkArgs fail, thumbData is invalid的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。