冻结向活动发送某些位图
基本上,我从图库接收图像的 URI,然后创建一个位图并希望发送到另一个活动进行显示:
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);
当我没有添加任何内容时,PreviewActivity 可以正常触发。然而,当我放置位图时,模拟器一直冻结,直到我强行关闭。这种情况在我身上发生过好几次,我总是尝试通过发送位图对象以外的其他内容来解决这个问题。
但这次我想我不能了。我不想通过传递图像的 Uri 来更改 API,因为其他一些活动已经向其发送位图。这是一个特例。
以下是冻结期间 LogCat 的输出:
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}}
并非所有位图都会发生这种情况。这个特定的位图来自大约 300K 的文件,但我不知道它是否与大小有关。这是我的错吗?有人经历过这个吗?
非常感谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
压缩后可能有 300KB - 但分辨率是多少?取宽度,乘以高度,然后再乘以 4。
你解题的方法是错误的。
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.