我正在尝试使用我自己的CWAC Camera自定义实现。我试图在我自己的 SimpleCameraHost 扩展上覆盖 saveImage 函数。这是我的代码:
欢迎您覆盖 saveImage(byte[]) 并使用 byte[] 执行其他操作,例如通过 Internet 发送它。saveImage(byte[]) 在后台线程上调用,因此您不必自己进行异步工作。
@Override
public void saveImage(byte[] byteArray) {
Intent myIntent = new Intent();
retData.putExtra("data", byteArray);
getActivity().setResult(Activity.RESULT_OK, myIntent);
getActivity().finish();
}
我正在三星 Galaxy S3 上进行测试,它运行良好,但是当我尝试使用前置摄像头时,我的应用程序冻结并崩溃。我没有对ActivityResult 做任何事情,所以它源自CameraFragment。不知道可能出了什么问题,因为文档说它已经用 S3 进行了测试。
编辑#2:
@Override
public Size getPictureSize(Parameters parameters) {
//return CameraUtils.getLargestPictureSize(parameters);
// TODO Auto-generated method stub
List<Camera.Size> list = parameters.getSupportedPictureSizes();
int targetWidth = 1280;
int width;
Camera.Size optimalSize= null;
for (Camera.Size size : list) {
width = size.width;
if (width==targetWidth) {
optimalSize = size;
return optimalSize;
} else if (width<targetWidth){
optimalSize = size;
return optimalSize;
} else if (width>targetWidth) {
optimalSize = size;
}
}
return optimalSize;
}
好的,所以我的代码绝对适用于将其传递给后置摄像头。当我尝试前置摄像头时,我仍然会崩溃。如果这是一个活页夹错误,我不会得到!!! FAILED BINDER TRANSACTION !!!
堆栈跟踪:
08-12 17:36:40.559: E/YYYY(1295): Height: 960 Width: 1280
08-12 17:36:40.969: D/DeviceProfile(1295): m0xx
08-12 17:36:40.969: I/CWAC-Camera(1295): begin rotateForRealz()
08-12 17:36:40.994: D/dalvikvm(1295): GC_FOR_ALLOC freed 1937K, 8% free 40478K/43911K, paused 26ms, total 26ms
08-12 17:36:40.994: D/AbsListView(1295): [unregisterDoubleTapMotionListener]
08-12 17:36:41.004: I/dalvikvm-heap(1295): Grow heap (frag case) to 44.943MB for 4915216-byte allocation
08-12 17:36:41.039: D/dalvikvm(1295): GC_FOR_ALLOC freed 5K, 8% free 45273K/48775K, paused 34ms, total 34ms
08-12 17:36:41.059: I/MotionRecognitionManager(1295): .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@436bd2e8
08-12 17:36:41.074: D/dalvikvm(1295): GC_CONCURRENT freed 21K, 8% free 45253K/48775K, paused 12ms+3ms, total 35ms
08-12 17:36:41.104: D/dalvikvm(1295): WAIT_FOR_CONCURRENT_GC blocked 0ms
08-12 17:36:41.129: D/dalvikvm(1295): GC_EXPLICIT freed <1K, 8% free 45252K/48775K, paused 2ms+3ms, total 26ms
08-12 17:36:41.149: D/dalvikvm(1295): GC_FOR_ALLOC freed 1K, 8% free 45256K/48775K, paused 15ms, total 15ms
08-12 17:36:41.154: I/dalvikvm-heap(1295): Grow heap (frag case) to 49.608MB for 4915216-byte allocation
08-12 17:36:41.184: D/dalvikvm(1295): GC_CONCURRENT freed 277K, 8% free 49778K/53639K, paused 11ms+4ms, total 29ms
08-12 17:36:41.184: D/dalvikvm(1295): WAIT_FOR_CONCURRENT_GC blocked 17ms
08-12 17:36:41.329: I/CWAC-Camera(1295): end rotateForRealz()
08-12 17:36:41.529: D/dalvikvm(1295): WAIT_FOR_CONCURRENT_GC blocked 0ms
08-12 17:36:41.559: D/dalvikvm(1295): GC_EXPLICIT freed 10806K, 24% free 40787K/53639K, paused 2ms+4ms, total 29ms
08-12 17:36:41.584: D/CameraView(1295): stopping preview
08-12 17:36:41.719: D/CameraView(1295): releasing camera
08-12 17:36:41.864: D/dalvikvm(3251): WAIT_FOR_CONCURRENT_GC blocked 0ms
08-12 17:36:41.899: D/dalvikvm(3268): WAIT_FOR_CONCURRENT_GC blocked 0ms
08-12 17:36:41.939: D/dalvikvm(3268): Trying to load lib /data/data/com.myapp.sample/lib/myappScore.so 0x429c6cf8
08-12 17:36:41.939: D/dalvikvm(3268): Added shared lib /data/data/com.myapp.sample/lib/myappScore.so 0x429c6cf8
08-12 17:36:41.939: D/dalvikvm(3268): No JNI_OnLoad found in /data/data/com.myapp.sample/lib/myappScore.so 0x429c6cf8, skipping init
08-12 17:36:41.969: I/ActionBarSherlock(3268): Registering ActionBarSherlockCompat with qualifier @com.actionbarsherlock.ActionBarSherlock$Implementation(api=7, dpi=-1)
08-12 17:36:41.969: I/ActionBarSherlock(3268): Registering ActionBarSherlockNative with qualifier @com.actionbarsherlock.ActionBarSherlock$Implementation(api=14, dpi=-1)
08-12 17:36:41.969: I/ActionBarSherlock(3268): Using implementation: ActionBarSherlockNative
08-12 17:36:41.969: D/ActionBarSherlock(3268): [<ctor>] activity: com.myapp.gui.details.ConvoDetailActivity@42a161a8, flags: 1
08-12 17:36:41.984: D/ActionBarSherlock(3268): [setContentView] layoutResId: 2130903062
08-12 17:36:42.004: D/dalvikvm(3268): GC_CONCURRENT freed 191K, 8% free 12330K/13319K, paused 13ms+12ms, total 36ms
08-12 17:36:42.019: D/dalvikvm(3268): GC_FOR_ALLOC freed 2K, 8% free 12330K/13319K, paused 10ms, total 10ms
08-12 17:36:42.019: I/dalvikvm-heap(3268): Grow heap (frag case) to 13.102MB for 353328-byte allocation
08-12 17:36:42.029: D/dalvikvm(3268): GC_FOR_ALLOC freed <1K, 8% free 12675K/13703K, paused 8ms, total 8ms
08-12 17:36:42.064: D/dalvikvm(3268): GC_FOR_ALLOC freed 5K, 8% free 12703K/13703K, paused 11ms, total 11ms
08-12 17:36:42.064: I/dalvikvm-heap(3268): Grow heap (frag case) to 15.473MB for 2457616-byte allocation
08-12 17:36:42.089: D/dalvikvm(3268): GC_CONCURRENT freed <1K, 7% free 15102K/16135K, paused 11ms+2ms, total 23ms
08-12 17:36:42.114: D/dalvikvm(3268): GC_FOR_ALLOC freed 0K, 7% free 15102K/16135K, paused 11ms, total 11ms
08-12 17:36:42.129: I/dalvikvm-heap(3268): Grow heap (frag case) to 24.847MB for 9830416-byte allocation
08-12 17:36:42.154: D/dalvikvm(3268): GC_CONCURRENT freed 0K, 5% free 24702K/25799K, paused 12ms+2ms, total 25ms
08-12 17:36:42.184: D/dalvikvm(3268): GC_FOR_ALLOC freed 2400K, 14% free 22725K/26247K, paused 12ms, total 12ms
08-12 17:36:42.234: D/dalvikvm(3268): GC_CONCURRENT freed 452K, 8% free 24310K/26247K, paused 3ms+12ms, total 26ms
08-12 17:36:42.234: D/AbsListView(3268): Get MotionRecognitionManager
08-12 17:36:42.244: D/AndroidRuntime(3268): Shutting down VM