我試圖將Bitmap傳遞給另一個活動,並且我使用ImageView
顯示來自其他活動的相同圖像。這就是我傳遞位圖的方式。將位圖傳遞給另一個活動以RunTimeException結束
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {
File out = new File(getFilesDir(), "newImage.jpg");
if(!out.exists()) {
Toast.makeText(getBaseContext(),
"Error while capturing image", Toast.LENGTH_LONG)
.show();
return;
}
Bitmap mBitmap = BitmapFactory.decodeFile(out.getAbsolutePath());
Intent bitIntent = new Intent(this, CameraTake.class);
bitIntent.putExtra("BitmapImage", mBitmap);
startActivity(bitIntent);
而且這是我獲得的價值:
Intent intent = getIntent();
bitmap= (Bitmap)intent.getParcelableExtra("BitmapImage");
ImageView im1 = (ImageView)findViewById(R.id.camOut);
im1.setImageBitmap(bitmap);
,當運行應用程序,這是我獲得的logcat:
> 10-17 08:32:11.241 16762-16762/obx.com.futurister E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: obx.com.futurister, PID: 16762
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { }} to activity {obx.com.futurister/obx.com.futurister.OptionChooser}: java.lang.RuntimeException: Failure from system
at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Failure from system
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at obx.com.futurister.OptionChooser.onActivityResult(OptionChooser.java:75)
at android.app.Activity.dispatchActivityResult(Activity.java:6428)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.os.TransactionTooLargeException: data parcel size 4915644 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2657)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at obx.com.futurister.OptionChooser.onActivityResult(OptionChooser.java:75)
at android.app.Activity.dispatchActivityResult(Activity.java:6428)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
at android.app.ActivityThread.-wrap16(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
在類似question,該解決方案建議使用圖像加載庫,我應該這樣做,還是可以很容易地解決這個問題?尋找專業答案。感謝
我認爲你應該通過圖像的路徑,不應該傳遞圖像! –
我使用這個:http://dharmendra4android.blogspot.in/2012/04/save-captured-image-to-applications.html來捕捉圖像,你能幫我找出這個路徑:/ – OBX
你在本地存儲中獲取圖像?使用'bitIntent。putExtra(「BitmapImage」,out.getAbsolutePath());'而不是'bitIntent.putExtra(「BitmapImage」,mBitmap);'。並在新的活動中,您將獲得並從路徑加載圖像! –