views:

233

answers:

1

Basically I receive the Image's URI from the Gallery, then created a Bitmap and want to send to another activity for displaying:

Uri imageUri = intent.getData();
mBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
Intent intent = new Intent(TakePictureActivity.this, PreviewActivity.class);
intent.putExtra(EXTRA_BITMAP_DATA, mBitmap);
startActivityForResult(intent, REQUEST_PREVIEW);

When I put nothing to the intent, the PreviewActivity can be fired normally. However when I put the bitmap, the emulator was freezing until I forced close. This has happened to me several times and I've always tried to work aroudn that by sending something else other than the Bitmap object.

But this time I guess I can't. I don't want to change the API by passing the image's Uri because some other Activities are already sending it bitmaps. This one is a special case.

Here is the output from LogCat during the freezing:

02-01 14:23:37.808: WARN/IInputConnectionWrapper(219): showStatusIcon on inactive InputConnection
02-01 14:23:37.899: INFO/ActivityManager(54): Displayed activity com.android.camera/.ImageGallery: 1456 ms (total 1456 ms)
02-01 14:23:40.009: DEBUG/dalvikvm(54): GC freed 2958 objects / 134576 bytes in 98ms
02-01 14:23:43.085: DEBUG/dalvikvm(219): GC freed 1712 objects / 372192 bytes in 80ms
02-01 14:23:43.085: DEBUG/Camera-JNI(219): release camera
02-01 14:23:47.489: INFO/WindowManager(54): Setting rotation to 1, animFlags=0
02-01 14:23:47.489: INFO/WindowManager(54): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=2 layout=18}
02-01 14:23:47.539: INFO/WindowManager(54): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=2 layout=18}
02-01 14:23:47.609: INFO/WindowManager(54): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=2 layout=18}
02-01 14:23:47.657: DEBUG/StatusBar(54): updateResources
02-01 14:23:47.848: DEBUG/dalvikvm(219): GC freed 200 objects / 7936 bytes in 212ms
02-01 14:23:48.109: INFO/ActivityManager(54): Starting activity: Intent { cmp=com.multinc.somo/.PreviewActivity (has extras) }
02-01 14:23:48.229: INFO/WindowManager(54): Setting rotation to 0, animFlags=0
02-01 14:23:48.259: INFO/WindowManager(54): Config changed: { scale=1.0 imsi=0/0 loc=en_US touch=3 keys=2/1/2 nav=3 orien=1 layout=18}
02-01 14:23:48.259: WARN/WindowManager(54): performLayoutAndPlaceSurfacesLocked called while in layout
02-01 14:23:48.417: ERROR/JavaBinder(54): !!! FAILED BINDER TRANSACTION !!!
02-01 14:23:48.417: DEBUG/StatusBar(54): updateResources
02-01 14:23:48.438: DEBUG/CameraService(31): CameraService::connect E (pid 219, client 0xd228)
02-01 14:23:48.438: DEBUG/CameraService(31): Client::Client E (pid 219)
02-01 14:23:48.438: DEBUG/CameraHardwareStub(31): initHeapLocked: preview size=176x144
02-01 14:23:48.438: ERROR/MediaPlayer(31): Unable to to create media player
02-01 14:23:48.438: ERROR/CameraService(31): Failed to load CameraService sounds.
02-01 14:23:48.438: ERROR/MediaPlayer(31): Unable to to create media player
02-01 14:23:48.438: ERROR/CameraService(31): Failed to load CameraService sounds.
02-01 14:23:48.461: DEBUG/CameraService(31): Client::Client X (pid 219)
02-01 14:23:48.461: DEBUG/CameraService(31): CameraService::connect X
02-01 14:23:48.461: DEBUG/CameraService(31): setPreviewDisplay(0x0) (pid 219)
02-01 14:23:48.461: DEBUG/CameraService(31): getParameters(picture-format=jpeg;picture-size=213x350;preview-format=yuv422sp;preview-frame-rate=15;preview-size=176x144)
02-01 14:23:48.461: DEBUG/CameraService(31): setParameters(picture-size=213x350;preview-frame-rate=15;preview-size=390x260;picture-format=jpeg;preview-format=yuv422sp)
02-01 14:23:48.461: DEBUG/CameraHardwareStub(31): initHeapLocked: preview size=390x260
02-01 14:23:48.461: DEBUG/CameraService(31): startPreview (pid 219)
02-01 14:23:48.461: DEBUG/CameraService(31): startCameraMode(0) (pid 219)
02-01 14:23:48.461: DEBUG/CameraService(31): mSurface is not set yet.
02-01 14:23:48.461: DEBUG/CameraService(31): startPreviewMode (pid 219)
02-01 14:23:48.533: DEBUG/Camera-JNI(219): release camera
02-01 14:23:48.533: DEBUG/CameraService(31): Client::disconnect() E (pid 219 client 0xd228)
02-01 14:23:48.533: DEBUG/CameraService(31): hardware teardown
02-01 14:23:48.589: DEBUG/CameraService(31): removeClient (pid 219) done
02-01 14:23:48.589: DEBUG/CameraService(31): Client::disconnect() X (pid 219)
02-01 14:23:48.589: DEBUG/CameraService(31): Client::~Client E (pid 31, client 0xd228)
02-01 14:23:48.589: DEBUG/CameraService(31): Client::disconnect() E (pid 31 client 0xd228)
02-01 14:23:48.589: DEBUG/CameraService(31): Client::~Client X (pid 31)
02-01 14:23:53.257: WARN/WindowManager(54): App freeze timeout expired.
02-01 14:23:53.259: WARN/WindowManager(54): Force clearing freeze: AppWindowToken{438f13f8 token=HistoryRecord{43871530 com.multinc.somo/.PreviewActivity}}

This does not happen with all bitmaps. This particular bitmap is from a ~300K file, but I dont know if it's related to the size. Is this my fault? Has anyone experienced this?

Thank you very much

A: 

It might be 300KB compressed - but what's the resolution. Take the width, multiply by height and multiply again by 4.

You are solving the problem wrong.

Will
The resolution is 640*480. Anyway, I profiled the method with a small image and noticed that most of the time was spent on Bitmap.nativeWriteToParcel, so I guess I should do it a different way anyway. So what is the normal way to send pictures between activities? Many thanks.
Po