Frage

I'm trying to use my own custom implementation of CWAC Camera. I am trying to override the saveImage function on my own extension of the SimpleCameraHost. This is my code:

You are welcome to override saveImage(byte[]) and do something else with the byte[], such as send it over the Internet. saveImage(byte[]) is called on a background thread, so you do not have to do your own asynchronous work.

@Override
public void saveImage(byte[] byteArray) {
    Intent myIntent = new Intent();
    retData.putExtra("data", byteArray);
    getActivity().setResult(Activity.RESULT_OK, myIntent);
    getActivity().finish();
}

I'm testing this on a samsung galaxy S3, and it works perfectly, but when I try to use the front facing camera, my application freezes up and crashes. I'm not doing anything onActivityResult, so it is originating from the CameraFragment. Don't know what could be wrong because the documentation says that it has been tested with an S3.

EDIT #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;

}

Okay, so my code definitely works for passing this through for the back camera. When I try the front facing camera, I still get a crash. If this was a binder error wouldn't I get !!! FAILED BINDER TRANSACTION !!!

Stacktrace:

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
War es hilfreich?

Lösung

I'm testing this on a samsung galaxy S3, and it works perfectly, but when I try to use the front facing camera, my application freezes up and crashes.

In the future, use LogCat to examine the Java stack trace with your crash.

In this case, my guess is that it is because you are trying to pass a multi-MB image file in an Intent extra, which will not work. Either use the image in the same activity where you take it, or pass it using other means (e.g., a careful handoff via a static data member).

Don't know what could be wrong because the documentation says that it has been tested with an S3.

And if you doubt this, try not overriding saveImage(), and see what happens.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top