0

Possible Duplicate:
How to pass image data from one activity to another activity?
pass a bitmap image from one activity to another

I tried to get a bitmap from view like below

     View s = ml.getRootView();
                s.setDrawingCacheEnabled(true);

            Bitmap  b = s.getDrawingCache();


                System.out.println(b.isRecycled());


                Log.e("ok","ok");
                Intent i=new Intent(CameraActivity.this,Update.class);
                 i.putExtra("data",b);
                 startActivity(i);
//                 s.setDrawingCacheEnabled(false);
                 s.setVisibility(View.GONE);
                 finish();

I tried to transfer the bitmap from this Activity to another,but it is showing me black screen and app gets crashed.
       s.setVisibility(View.GONE); If I dont give this statement it is showing me this modified Activity and then it is showing Black screen.

I think it is taking much time to transfer this bitmap.

How can I solve this issue?

please help

Thanks

Logcat after getting Black screen

12-06 11:23:34.654: E/AndroidRuntime(16900): FATAL EXCEPTION: main
12-06 11:23:34.654: E/AndroidRuntime(16900): java.lang.NullPointerException
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2595)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.app.ActivityThread.access$1800(ActivityThread.java:124)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.os.Looper.loop(Looper.java:123)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at android.app.ActivityThread.main(ActivityThread.java:3806)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at java.lang.reflect.Method.invokeNative(Native Method)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at java.lang.reflect.Method.invoke(Method.java:507)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-06 11:23:34.654: E/AndroidRuntime(16900):    at dalvik.system.NativeStart.main(Native Method)
12-06 11:23:36.490: W/InputManagerService(1318): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40a84730
Community
  • 1
  • 1
user1871951
  • 105
  • 3
  • 8

1 Answers1

2

You are passing Bitmap into Intent and get bitmap in next activity from bundle, but the problem is if your Bitmap/Image size is big at that time the image is not load in next activity.

Use below 2 Solutions to solve this issue.

1) First Convert Image into Byte Array and then pass into Intent and in next activity get byte array from Bundle and Convert into Image(Bitmap) and set into ImageView.

Convert Bitmap to Byte Array:-

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Pass byte array into intent:-

Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);

Get Byte Array from Bundle and Convert into Bitmap Image:-

Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);

image.setImageBitmap(bmp);

2) First Save image into SDCard and in next activity set this image into ImageView.

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128