在我的应用程序中,当我尝试在不使用压缩技术的情况下在图像视图中显示图像时,我的应用程序崩溃了。以下是完整的代码和logcat
10-30 21:19:53.779: E/Trace(1817): error opening trace file: No such file or directory (2)
10-30 21:20:12.789: E/AndroidRuntime(1817): FATAL EXCEPTION: main
10-30 21:20:12.789: E/AndroidRuntime(1817): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { act=inline-data dat=content (has extras) }} to activity {com.example.checkactivities/com.example.checkactivities.Activity2}: java.nio.BufferUnderflowException
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread.deliverResults(ActivityThread.java:3622)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3672)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread.access$1100(ActivityThread.java:151)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.os.Looper.loop(Looper.java:155)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread.main(ActivityThread.java:5454)
10-30 21:20:12.789: E/AndroidRuntime(1817): at java.lang.reflect.Method.invokeNative(Native Method)
10-30 21:20:12.789: E/AndroidRuntime(1817): at java.lang.reflect.Method.invoke(Method.java:511)
10-30 21:20:12.789: E/AndroidRuntime(1817): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
10-30 21:20:12.789: E/AndroidRuntime(1817): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
10-30 21:20:12.789: E/AndroidRuntime(1817): at dalvik.system.NativeStart.main(Native Method)
10-30 21:20:12.789: E/AndroidRuntime(1817): Caused by: java.nio.BufferUnderflowException
10-30 21:20:12.789: E/AndroidRuntime(1817): at java.nio.Buffer.checkGetBounds(Buffer.java:177)
10-30 21:20:12.789: E/AndroidRuntime(1817): at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:63)
10-30 21:20:12.789: E/AndroidRuntime(1817): at com.example.checkactivities.Activity2.onActivityResult(Activity2.java:476)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.Activity.dispatchActivityResult(Activity.java:5275)
10-30 21:20:12.789: E/AndroidRuntime(1817): at android.app.ActivityThread.deliverResults(ActivityThread.java:3618)
10-30 21:20:12.789: E/AndroidRuntime(1817): ... 11 more
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
int bytes = thumbnail.getWidth()*thumbnail.getHeight()*4;
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
thumbnail.copyPixelsToBuffer(buffer);
byte[] bytes1 = new byte[bytes];
buffer.get(bytes1, 0, bytes1.length);
byte[] b = buffer.array();
String ImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(ImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,bytarray.length);
imageView11.setImageBitmap(bmimage);