将base64 imageString转换为位图以在ImageView中显示,在位图中显示为null

(编辑)的

logcat的:

 03-24 04:29:43.816: E/OnResponse(15392): ÿØÿà  JFIF            ÿí  Photoshop 3.0  8BIM          g  9dXpsI_ORS9jWIcxWfWe(  bFBMD01000abe030000070e0000c51a0000161c0000251d0000bc2000007f350000fc370000323a00003f3c0000f4620000ÿâICC_PROFILE      lcms    mntrRGB XYZ Ü        )  9acspAPPL                                                    öÖ          Ó-lcms                                                                                               03-24 04:29:43.816: E/OnResponse(15392): desc      ü      ^cprt    \      wtpt    h      bkpt    |      rXYZ          gXYZ    ¤      bXYZ    ¸      rTRC    Ì      @gTRC    Ì      @bTRC    Ì      @desc              c2                                                                                                                                                                    text        FB    XYZ             öÖ          Ó-XYZ                 3    ¤XYZ             o¢    8õ    XYZ             b    ·    ÚXYZ             $         ¶Ïcurv                    ËÉckö?Q4!ñ)2;FQw]íkpz±|¬i¿}ÓÃé0ÿÿÿÛ  C   03-24 04:29:43.816: E/OnResponse(15392): "##! %*5-%'2( .?/279<<<$-BFA:F5;<9ÿÛ  C 03-24 04:29:43.816: E/OnResponse(15392): 9& &99999999999999999999999999999999999999999999999999ÿ  ¸¸  "  ÿÄ                            ÿÄ                          ÿÄ                          ÿÚ          íÐÙG,!.Ph5ð8ò÷¸¥®ÐàÔ§DUdº de  kP'.¤ÅS BG ìóölâvw@+.ÆÖ®©$¸ Ø 03-24 04:29:43.816: E/OnResponse(15392): K¥Yp ³ºXC¹O/)u RÉuEÊ$£³UÂP©hL^ÅÌ ·üûÌ%§ EU-1i6Ss©,ÞÌõ®{·W¹k`¤I!kwt%ÙeP¦*Ôªóï-¿ 03-24 04:29:43.816: E/OnResponse(15392):  l"4áá#^-KSIBá¯S¨jYeîÌùucÓq}Lvå^ jÍ [Bz¾·í'nUï#tE ÂQ(äf)Uw(5ݨG/cUÙÀSAIÓ(´ÌÑY.,±iíÒ«Bଽ^pvf;TAX,KÄEµ XbìÜHqßìx¯Wf ¬«R\¤.ªªì#IOYçx=ÿ  7+J%g(ªÉM*ÖhÙ¶ìíZMøعs^²Èó¡fº(%F¬î\ÓF¥§*ÇÈÉ+«Çu{Hë¥]G4Q%A]Eñî>±3¦Y:,tÖØ&:×F3Óf]¡9ÖõQ9Zã  ÕZ3¼9zIÖy¶ÓT ÓPֺϫ@eÎv ìô}¿%ên[Tz)h6v¹n,h°°?ÅfìÓOÇZ1ЮÑCdÖJí³íÁ±ÌN·VcÔpÐèkEÃ`W°+5hg `Eçg4µãß4VzÆÏ[ã½-x7¨A`ºÊD5Wå®ky{º¬ZùöeÔÏG¶Br VD&´³· &µçY׬fLDLEP²¬X°2®æ¹\{Æ|°o{¾¦®w* Kªj2ÖåÉâ  nkv¼yöÐC3·±MÎWÆ%ÈmÞ e  æÌè*ÍsgJSWPØ+bn]@0×<¸7cßnçé³Ü߸pª(©AÕÂÖV*ϯNlë^¬:ùõÝjfz½©vuwV4nvFåf°ÒT±0&§c,³ Yv#tUH\%Ø\ÚÇ6¹-úr[n}ÃêÈÊ`J¡£! t¬ªÍ£<7VMXë³Fmú¹«vwED¥pÐlÌ6k!m+[lI@2Ò¬êÂhFè© jl%\Gfß Ìäï¿>o!jJ²Ìn¡,®XJg"<ÊH!»±ô±ÔÞ¶c¦¥ÙÝÚÙ `HwW¨Â]¡Â;R´eZ¦Í.¡T`-MSs3ståS|˧ØY¢VÛ1ÌA^¶"¹Id"¹¹=,»ùÄô0o¾=©7¥ù¦u¶ò:WÚa..ÊAÙ F®tXhÐåJB#)Â1bj±jhÙÍÍÒæôåV,×-^ãÃûPúuë9rj#D^®4WFªêÞ_sÇÓÈáú(?¥r2³¡'äa¥y]yÖfúRàîèGf´¦vuóñCYë³Gj¹$t& 03-24 04:29:43.816: E/OnResponse(15392): ftK4]Oc¾yØ;u^ØÎûÀ!×ÎÖZ±yVµv ÐÙËò¿/.ÃÇìr±Ó6ìÚõdÌél0MU±:æ3¤¼æµ¸é[qêÍ}´õà\ÈÚÍg³å^{0½*ÃÓÎò£¨Äàb«Óæëë/£¬Îo|½æîV{ðUµr®1É.¥Ü. ¥!ù±ÐyÝNo>ØõfÔ\ãuvc=C¨².¥H:M$º$£\é:· dt(ÓZÆP×ró¬³P-P¥µR¯ü]9wØÕóínnÿ  +£æùç pçRv¢E¢òêNw1j>]¸ë65.çլ첢² 1ì0aÝÉVrÀ¦] j¬eµpïÍeä×]9vW&;§ÑùßAßÆéɽc®|n Ù!æYbÔ£¢èLVwñïËÍÕâGUÙuã©°hC-eEg~u 03-24 04:29:43.816: E/OnResponse(15392): MnK9Û0ìW¥Îzr¥º.êVÅBrjǬKOx%³*·µÍßÛÍììòúÉrCÍBcAXrÅ1Þ;Óçã¦Xusé jLS[uXïFuJf¡«²Ãôb|t3µ¶¢£(XÂÐùwË£ÒÌÖ¢#:qê^o·T  ä%gÈ`*WQlJ N×EÌéx®4»õáÓÃÓ±n6f6 03-24 04:29:43.816: D/skia(15392): --- SkImageDecoder::Factory returned null 03-24 04:29:43.816: E/myBitmap(15392): null 03-24 04:29:43.816: D/AndroidRuntime(15392): Shutting down VM 03-24 04:29:43.817: E/AndroidRuntime(15392): FATAL EXCEPTION: main 03-24 04:29:43.817: E/AndroidRuntime(15392): Process: com.steve.test, PID: 15392 03-24 04:29:43.817: E/AndroidRuntime(15392): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:596) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:121) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.handleCallback(Handler.java:739) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.dispatchMessage(Handler.java:95) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Looper.loop(Looper.java:135) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.app.ActivityThread.main(ActivityThread.java:5221) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Native Method) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Method.java:372) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)  03-24 04:29:43.816: E/OnResponse(15392): ÿØÿà  JFIF            ÿí  Photoshop 3.0  8BIM          g  9dXpsI_ORS9jWIcxWfWe(  bFBMD01000abe030000070e0000c51a0000161c0000251d0000bc2000007f350000fc370000323a00003f3c0000f4620000ÿâICC_PROFILE      lcms    mntrRGB XYZ Ü        )  9acspAPPL                                                    öÖ          Ó-lcms                                                                                               03-24 04:29:43.816: E/OnResponse(15392): desc      ü      ^cprt    \      wtpt    h      bkpt    |      rXYZ          gXYZ    ¤      bXYZ    ¸      rTRC    Ì      @gTRC    Ì      @bTRC    Ì      @desc              c2                                                                                                                                                                    text        FB    XYZ             öÖ          Ó-XYZ                 3    ¤XYZ             o¢    8õ    XYZ             b    ·    ÚXYZ             $         ¶Ïcurv                    ËÉckö?Q4!ñ)2;FQw]íkpz±|¬i¿}ÓÃé0ÿÿÿÛ  C   03-24 04:29:43.816: E/OnResponse(15392): "##! %*5-%'2( .?/279<<<$-BFA:F5;<9ÿÛ  C 03-24 04:29:43.816: E/OnResponse(15392): 9& &99999999999999999999999999999999999999999999999999ÿ  ¸¸  "  ÿÄ                            ÿÄ                          ÿÄ                          ÿÚ          íÐÙG,!.Ph5ð8ò÷¸¥®ÐàÔ§DUdº de  kP'.¤ÅS BG ìóölâvw@+.ÆÖ®©$¸ Ø 03-24 04:29:43.816: E/OnResponse(15392): K¥Yp ³ºXC¹O/)u RÉuEÊ$£³UÂP©hL^ÅÌ ·üûÌ%§ EU-1i6Ss©,ÞÌõ®{·W¹k`¤I!kwt%ÙeP¦*Ôªóï-¿ 03-24 04:29:43.816: E/OnResponse(15392):  l"4áá#^-KSIBá¯S¨jYeîÌùucÓq}Lvå^ jÍ [Bz¾·í'nUï#tE ÂQ(äf)Uw(5ݨG/cUÙÀSAIÓ(´ÌÑY.,±iíÒ«Bଽ^pvf;TAX,KÄEµ XbìÜHqßìx¯Wf ¬«R\¤.ªªì#IOYçx=ÿ  7+J%g(ªÉM*ÖhÙ¶ìíZMøعs^²Èó¡fº(%F¬î\ÓF¥§*ÇÈÉ+«Çu{Hë¥]G4Q%A]Eñî>±3¦Y:,tÖØ&:×F3Óf]¡9ÖõQ9Zã  ÕZ3¼9zIÖy¶ÓT ÓPֺϫ@eÎv ìô}¿%ên[Tz)h6v¹n,h°°?ÅfìÓOÇZ1ЮÑCdÖJí³íÁ±ÌN·VcÔpÐèkEÃ`W°+5hg `Eçg4µãß4VzÆÏ[ã½-x7¨A`ºÊD5Wå®ky{º¬ZùöeÔÏG¶Br VD&´³· &µçY׬fLDLEP²¬X°2®æ¹\{Æ|°o{¾¦®w* Kªj2ÖåÉâ  nkv¼yöÐC3·±MÎWÆ%ÈmÞ e  æÌè*ÍsgJSWPØ+bn]@0×<¸7cßnçé³Ü߸pª(©AÕÂÖV*ϯNlë^¬:ùõÝjfz½©vuwV4nvFåf°ÒT±0&§c,³ Yv#tUH\%Ø\ÚÇ6¹-úr[n}ÃêÈÊ`J¡£! t¬ªÍ£<7VMXë³Fmú¹«vwED¥pÐlÌ6k!m+[lI@2Ò¬êÂhFè© jl%\Gfß Ìäï¿>o!jJ²Ìn¡,®XJg"<ÊH!»±ô±ÔÞ¶c¦¥ÙÝÚÙ `HwW¨Â]¡Â;R´eZ¦Í.¡T`-MSs3ståS|˧ØY¢VÛ1ÌA^¶"¹Id"¹¹=,»ùÄô0o¾=©7¥ù¦u¶ò:WÚa..ÊAÙ F®tXhÐåJB#)Â1bj±jhÙÍÍÒæôåV,×-^ãÃûPúuë9rj#D^®4WFªêÞ_sÇÓÈáú(?¥r2³¡'äa¥y]yÖfúRàîèGf´¦vuóñCYë³Gj¹$t& 03-24 04:29:43.816: E/OnResponse(15392): ftK4]Oc¾yØ;u^ØÎûÀ!×ÎÖZ±yVµv ÐÙËò¿/.ÃÇìr±Ó6ìÚõdÌél0MU±:æ3¤¼æµ¸é[qêÍ}´õà\ÈÚÍg³å^{0½*ÃÓÎò£¨Äàb«Óæëë/£¬Îo|½æîV{ðUµr®1É.¥Ü. ¥!ù±ÐyÝNo>ØõfÔ\ãuvc=C¨².¥H:M$º$£\é:· dt(ÓZÆP×ró¬³P-P¥µR¯ü]9wØÕóínnÿ  +£æùç pçRv¢E¢òêNw1j>]¸ë65.çլ첢² 1ì0aÝÉVrÀ¦] j¬eµpïÍeä×]9vW&;§ÑùßAßÆéɽc®|n Ù!æYbÔ£¢èLVwñïËÍÕâGUÙuã©°hC-eEg~u 03-24 04:29:43.816: E/OnResponse(15392): MnK9Û0ìW¥Îzr¥º.êVÅBrjǬKOx%³*·µÍßÛÍììòúÉrCÍBcAXrÅ1Þ;Óçã¦Xusé jLS[uXïFuJf¡«²Ãôb|t3µ¶¢£(XÂÐùwË£ÒÌÖ¢#:qê^o·T  ä%gÈ`*WQlJ N×EÌéx®4»õáÓÃÓ±n6f6 03-24 04:29:43.816: D/skia(15392): --- SkImageDecoder::Factory returned null 03-24 04:29:43.816: E/myBitmap(15392): null 03-24 04:29:43.816: D/AndroidRuntime(15392): Shutting down VM 03-24 04:29:43.817: E/AndroidRuntime(15392): FATAL EXCEPTION: main 03-24 04:29:43.817: E/AndroidRuntime(15392): Process: com.steve.test, PID: 15392 03-24 04:29:43.817: E/AndroidRuntime(15392): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:596) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:121) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.handleCallback(Handler.java:739) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.dispatchMessage(Handler.java:95) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Looper.loop(Looper.java:135) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.app.ActivityThread.main(ActivityThread.java:5221) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Native Method) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Method.java:372) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)  03-24 04:29:43.816: E/OnResponse(15392): ÿØÿà  JFIF            ÿí  Photoshop 3.0  8BIM          g  9dXpsI_ORS9jWIcxWfWe(  bFBMD01000abe030000070e0000c51a0000161c0000251d0000bc2000007f350000fc370000323a00003f3c0000f4620000ÿâICC_PROFILE      lcms    mntrRGB XYZ Ü        )  9acspAPPL                                                    öÖ          Ó-lcms                                                                                               03-24 04:29:43.816: E/OnResponse(15392): desc      ü      ^cprt    \      wtpt    h      bkpt    |      rXYZ          gXYZ    ¤      bXYZ    ¸      rTRC    Ì      @gTRC    Ì      @bTRC    Ì      @desc              c2                                                                                                                                                                    text        FB    XYZ             öÖ          Ó-XYZ                 3    ¤XYZ             o¢    8õ    XYZ             b    ·    ÚXYZ             $         ¶Ïcurv                    ËÉckö?Q4!ñ)2;FQw]íkpz±|¬i¿}ÓÃé0ÿÿÿÛ  C   03-24 04:29:43.816: E/OnResponse(15392): "##! %*5-%'2( .?/279<<<$-BFA:F5;<9ÿÛ  C 03-24 04:29:43.816: E/OnResponse(15392): 9& &99999999999999999999999999999999999999999999999999ÿ  ¸¸  "  ÿÄ                            ÿÄ                          ÿÄ                          ÿÚ          íÐÙG,!.Ph5ð8ò÷¸¥®ÐàÔ§DUdº de  kP'.¤ÅS BG ìóölâvw@+.ÆÖ®©$¸ Ø 03-24 04:29:43.816: E/OnResponse(15392): K¥Yp ³ºXC¹O/)u RÉuEÊ$£³UÂP©hL^ÅÌ ·üûÌ%§ EU-1i6Ss©,ÞÌõ®{·W¹k`¤I!kwt%ÙeP¦*Ôªóï-¿ 03-24 04:29:43.816: E/OnResponse(15392):  l"4áá#^-KSIBá¯S¨jYeîÌùucÓq}Lvå^ jÍ [Bz¾·í'nUï#tE ÂQ(äf)Uw(5ݨG/cUÙÀSAIÓ(´ÌÑY.,±iíÒ«Bଽ^pvf;TAX,KÄEµ XbìÜHqßìx¯Wf ¬«R\¤.ªªì#IOYçx=ÿ  7+J%g(ªÉM*ÖhÙ¶ìíZMøعs^²Èó¡fº(%F¬î\ÓF¥§*ÇÈÉ+«Çu{Hë¥]G4Q%A]Eñî>±3¦Y:,tÖØ&:×F3Óf]¡9ÖõQ9Zã  ÕZ3¼9zIÖy¶ÓT ÓPֺϫ@eÎv ìô}¿%ên[Tz)h6v¹n,h°°?ÅfìÓOÇZ1ЮÑCdÖJí³íÁ±ÌN·VcÔpÐèkEÃ`W°+5hg `Eçg4µãß4VzÆÏ[ã½-x7¨A`ºÊD5Wå®ky{º¬ZùöeÔÏG¶Br VD&´³· &µçY׬fLDLEP²¬X°2®æ¹\{Æ|°o{¾¦®w* Kªj2ÖåÉâ  nkv¼yöÐC3·±MÎWÆ%ÈmÞ e  æÌè*ÍsgJSWPØ+bn]@0×<¸7cßnçé³Ü߸pª(©AÕÂÖV*ϯNlë^¬:ùõÝjfz½©vuwV4nvFåf°ÒT±0&§c,³ Yv#tUH\%Ø\ÚÇ6¹-úr[n}ÃêÈÊ`J¡£! t¬ªÍ£<7VMXë³Fmú¹«vwED¥pÐlÌ6k!m+[lI@2Ò¬êÂhFè© jl%\Gfß Ìäï¿>o!jJ²Ìn¡,®XJg"<ÊH!»±ô±ÔÞ¶c¦¥ÙÝÚÙ `HwW¨Â]¡Â;R´eZ¦Í.¡T`-MSs3ståS|˧ØY¢VÛ1ÌA^¶"¹Id"¹¹=,»ùÄô0o¾=©7¥ù¦u¶ò:WÚa..ÊAÙ F®tXhÐåJB#)Â1bj±jhÙÍÍÒæôåV,×-^ãÃûPúuë9rj#D^®4WFªêÞ_sÇÓÈáú(?¥r2³¡'äa¥y]yÖfúRàîèGf´¦vuóñCYë³Gj¹$t& 03-24 04:29:43.816: E/OnResponse(15392): ftK4]Oc¾yØ;u^ØÎûÀ!×ÎÖZ±yVµv ÐÙËò¿/.ÃÇìr±Ó6ìÚõdÌél0MU±:æ3¤¼æµ¸é[qêÍ}´õà\ÈÚÍg³å^{0½*ÃÓÎò£¨Äàb«Óæëë/£¬Îo|½æîV{ðUµr®1É.¥Ü. ¥!ù±ÐyÝNo>ØõfÔ\ãuvc=C¨².¥H:M$º$£\é:· dt(ÓZÆP×ró¬³P-P¥µR¯ü]9wØÕóínnÿ  +£æùç pçRv¢E¢òêNw1j>]¸ë65.çլ첢² 1ì0aÝÉVrÀ¦] j¬eµpïÍeä×]9vW&;§ÑùßAßÆéɽc®|n Ù!æYbÔ£¢èLVwñïËÍÕâGUÙuã©°hC-eEg~u 03-24 04:29:43.816: E/OnResponse(15392): MnK9Û0ìW¥Îzr¥º.êVÅBrjǬKOx%³*·µÍßÛÍììòúÉrCÍBcAXrÅ1Þ;Óçã¦Xusé jLS[uXïFuJf¡«²Ãôb|t3µ¶¢£(XÂÐùwË£ÒÌÖ¢#:qê^o·T  ä%gÈ`*WQlJ N×EÌéx®4»õáÓÃÓ±n6f6 03-24 04:29:43.816: D/skia(15392): --- SkImageDecoder::Factory returned null 03-24 04:29:43.816: E/myBitmap(15392): null 03-24 04:29:43.816: D/AndroidRuntime(15392): Shutting down VM 03-24 04:29:43.817: E/AndroidRuntime(15392): FATAL EXCEPTION: main 03-24 04:29:43.817: E/AndroidRuntime(15392): Process: com.steve.test, PID: 15392 03-24 04:29:43.817: E/AndroidRuntime(15392): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:596) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:121) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.steve.test.SecondActivity$1.onResponse(SecondActivity.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:1) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.handleCallback(Handler.java:739) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Handler.dispatchMessage(Handler.java:95) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.os.Looper.loop(Looper.java:135) 03-24 04:29:43.817: E/AndroidRuntime(15392): at android.app.ActivityThread.main(ActivityThread.java:5221) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Native Method) 03-24 04:29:43.817: E/AndroidRuntime(15392): at java.lang.reflect.Method.invoke(Method.java:372) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 03-24 04:29:43.817: E/AndroidRuntime(15392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

SecondActivity.java:

  public class SecondActivity extends AppCompatActivity { String base64String; Bitmap bitmap; ImageView img ; String userValidationURL, base64; byte[] data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_activity); img = (ImageView)findViewById(R.id.imageView); base64String = "GvygDaYb64wUon0lxp2H1458543376"; userValidationURL = "http://example.com/api/v1/filedownloader.json?file=GvygDaYb64wUon0lxp2H1458543376"; hitSearchApi(); } private void hitSearchApi(){ Log.e("userValidationUrl", userValidationURL); StringRequest request = new StringRequest(Request.Method.GET, userValidationURL, new Response.Listener<String>() { @Override public void onResponse(String response) { if(response != null && !response.startsWith("<HTML>")){ Log.e("OnResponse", response); byte[] decodedString = Base64.decode("GvygDaYb64wUon0lxp2H1458543376", Base64.DEFAULT); Bitmap myBitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); Log.e("mybitmap", ""+myBitmap); img.setImageBitmap(Bitmap.createScaledBitmap(myBitmap, img.getWidth(), img.getHeight(), false)); dialog.dismiss(); }else{ Log.e("onResponseElse", "onResponseElse"); dialog.dismiss(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { if(error != null){ Log.e("error", error.toString()); dialog.dismiss(); } } }){ @Override protected Map<String,String> getParams(){ Map<String,String> params = new HashMap<String, String>(); params.put("file", base64String); Log.e("paramsImg", ""+params); return params; } @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String,String> params = new HashMap<String, String>(); params.put("Content-Type","application/x-www-form-urlencoded"); return params; } }; RequestQueue queue = Volley.newRequestQueue(SecondActivity.this); queue.add(request); queue.getCache().remove(userValidationURL); } } 

这段代码有什么问题? 为什么我null图中变为null 任何人都可以帮助我。

Solutions Collecting From Web of "将base64 imageString转换为位图以在ImageView中显示,在位图中显示为null"

03-24 04:29:43.816:D / skia(15392):— SkImageDecoder :: Factory返回null

这表示BitmapFactory.decode的input在某些方面是无效的。

下面我列举一些可能欺骗你的场景,但是不确定哪一个适用,因为你没有透露真正的Url,你发布的代码甚至不试图解码来自networking的数据。

Base64填充

您的硬编码inputstring是GvygDaYb64wUon0lxp2H1458543376 ,它不是有效的Base64编码string。 要看看为什么在页面上input: http : //string-functions.com/base64decode.aspx ,它会说:

Base-64字符数组的长度无效。

把它GvygDaYb64wUon0lxp2H1458543376== (注意结尾),它会显示你奇怪的字形,但这是因为它是二进制数据,所以它成功解码。

奇怪的是Base64类应该抛出一个exception,当填充缺失,你没有得到…

您还可以在Chrome浏览器中查看编码string的内容,将其input到新选项卡的地址栏中(逗号后replace,请参阅有效示例 ):

 data:image/png;base64,GvygDaYb64wUon0lxp2H1458543376== 

我看到一个小方块,这可能不是图像(见下一节)。

Base64格式

你试图解码的样本也是一些奇怪的格式。 这不是Android系统支持的PNG / GIF / JPEG文件,它缺less标题。 看看支持的格式列表: http : //developer.android.com/guide/appendix/media-formats.html (向下滚动到图片),这些是你可以加载的数据types。

我试图用我的笔记本电脑上的多个成像软件加载这个短字节[],没有把它识别为图像文件,我同意他们,我不能在hex编辑器中看到任何图像。

Base64 – 不是!

如果你想解码variablesresponse确保它是一个Base64编码的string。 上面的日志里有什么是JPEG文件,但可能是坏的。 注意你正在使用StringRequest,只有当你真的得到一个由[a-zA-Z0-9+/=]字符组成的Base64string时才会起作用。

要读取二进制数据,您需要根据您的networking库启动不同types的请求,但关键在于,如果您以string格式接收二进制数据,这意味着应用了一些文本编码,但是二进制数据没有字符编码,只是纯粹的0x00-0xFF字节没有任何解释。

二进制数据上的BitmapFactory.decode只有在您从networking库或者InputStreamReader s也具有关联的二进制数据错误的文本编码)接收到byte[]时才有效。

正如你可以从日志中看到的那样

E / myBitmap:null

这意味着你不能解码位图。 请参考这个答案

将Base64string转换为位图

还要确保你正在采取适当的方法取决于你是否收到

 data:image/jpg;base64 

在base64编码的string中。 这是要么切片的一部分

 data:image/jpg;base64 

从string中使用Base64.DEFAULT解码

或者使用Base64.URL_SAFE如果你正在切片。

编辑:更改loadImage的以下行

 Bitmap myBitmap = BitmapFactory.decodeStream(input); 

 BufferedReader in = new BufferedReader(new InputStreamReader(input)); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); String encodedImage = response.toString(); byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT); Bitmap myBitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 

另外,如果它不起作用,让我知道encodedImagestring的值是什么。 还要确保

 data:image/jpg;base64 

没有被传递的答复。

如果您在validationstring是否为图片时遇到问题,可以使用以下命令创build一个简单的html页面

 <!DOCTYPE html> <html> <head> <title>Base 64 Sample</title> </head> <body> <img src="data:image/< png/jpeg/gif etc goes here >;base64,< image content goes here>"> </body> </html> 

用适当的内容replace“<”,“>”内的内容,并在浏览器中打开html页面。 或者,您可以转到此链接并在其中粘贴string。

你得到正确的base64编码的string。 只要使用下面的代码将该string转换为bitmap

 byte[] decodedString = Base64.decode(StrBase64, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); imageView1.setImageBitmap(decodedByte); 

您传递给bitMapToString函数的位bitMapToString null因此您将收到null对象错误。

你在loadImage();中没有得到正确的bitmap loadImage(); 所以做出改变

 InputStream input = connection.getInputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(input); Bitmap myBitmap = BitmapFactory.decodeStream(input); 

这样你将得到bitmap

实际上,一个Base64string有这么多字符。 您的Base64string不正确,请将图像上传到本网站以获取Base64string。 改为在你的代码中使用该string。

 byte[] decodedString = Base64.decode(StrBase64, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); imageView1.setImageBitmap(decodedByte);