3

I want to get frames from camera's phone and send it to "handler", so i do like below:

mCamera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() {
        int frame = 0;

        public synchronized void onPreviewFrame(byte[] data, Camera camera) {
            try {
                super.clone();
            } catch (CloneNotSupportedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            frame++;
            if (frame == 1) {
                timestamp = System.currentTimeMillis();
            }
            duration = (System.currentTimeMillis() - timestamp) / 1000;
            Log.v("Time", "Time = " + duration);
            System.out.println("" + frame);

            try {
                camera.addCallbackBuffer(data);
                if (duration != 0) {
                    // dataArr.add(data);
                    if (duration <= 15) {
                        msg = handler.obtainMessage();
                        msg.obj = (byte[]) data.clone();
                        handler.sendMessage(msg);
                        // System.out.println("Sent from main!!");
                    } else {
                        stopVideo();
                    }                       
                }
                // Log.v("time", ""+dataArr.size());

But when i run my application, i got "out of memory on a 460816-byte allocation" error. My logcat likes:

FATAL EXCEPTION:main
java.lang.OutOfMemoryError
java.lang.Object.internalClone(Native Method)
java.lang .Object.clone(Object.jave.158)
at com.example.dechme.MainActivity$3.onPreviewFrame(MainActivity.java:151)

And line 151 in MainActivity is

    msg.obj = (byte[]) data.clone();

I don't know how to fix this error. Please tell me if you have some clues. Thanks

user3629083
  • 103
  • 2
  • 5
  • Have you check on http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966 – Shan Markus May 20 '14 at 01:31

0 Answers0