Java Code Examples for android.hardware.Camera#setOneShotPreviewCallback()

The following examples show how to use android.hardware.Camera#setOneShotPreviewCallback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraManager.java    From StarBarcode with Apache License 2.0 6 votes vote down vote up
/**
 * 停止预览
 */
@Override
public void stopPreview() {
    if (isOpenCamera() && previewing) {
        try {
            Camera theCamera = mCamera.getCamera();
            if (focusManager != null) {
                focusManager.stop();
                focusManager = null;
            }
            theCamera.setOneShotPreviewCallback(null);
            theCamera.stopPreview();
            previewing = false;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: CameraManager.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message)
{
    Camera theCamera = camera;
    if (theCamera != null && previewing)
    {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 3
Source File: CameraManager.java    From ScanZbar with Apache License 2.0 5 votes vote down vote up
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        // 绑定相机回调函数,当预览界面准备就绪后会回调Camera.PreviewCallback.onPreviewFrame
       theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 4
Source File: ZXingScannerView.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if(mResultHandler == null) {
        return;
    }
    
    try {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = parameters.getPreviewSize();
        int width = size.width;
        int height = size.height;

        if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
            byte[] rotatedData = new byte[data.length];
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++)
                    rotatedData[x * height + height - y - 1] = data[x + y * width];
            }
            int tmp = width;
            width = height;
            height = tmp;
            data = rotatedData;
        }

        Result rawResult = null;
        PlanarYUVLuminanceSource source = buildLuminanceSource(data, width, height);

        if (source != null) {
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            try {
                rawResult = mMultiFormatReader.decodeWithState(bitmap);
            } catch (ReaderException re) {
                // continue
            } catch (NullPointerException npe) {
                // This is terrible
            } catch (ArrayIndexOutOfBoundsException aoe) {

            } finally {
                mMultiFormatReader.reset();
            }
        }

        final Result finalRawResult = rawResult;

        if (finalRawResult != null) {
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {
                @Override
                public void run() {
                    // Stopping the preview can take a little long.
                    // So we want to set result handler to null to discard subsequent calls to
                    // onPreviewFrame.
                    ResultHandler tmpResultHandler = mResultHandler;
                    mResultHandler = null;

                    stopCameraPreview();
                    if (tmpResultHandler != null) {
                        tmpResultHandler.handleResult(finalRawResult);
                    }
                }
            });
        } else {
            camera.setOneShotPreviewCallback(this);
        }
    } catch(RuntimeException e) {
        // TODO: Terrible hack. It is possible that this method is invoked after camera is released.
        Log.e(TAG, e.toString(), e);
    }
}
 
Example 5
Source File: RNCameraComponentView.java    From react-native-camera-android with MIT License 4 votes vote down vote up
public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();
    int width = size.width;
    int height = size.height;
    if(DisplayUtils.getScreenOrientation(this.getContext()) == 1) {
        byte[] rawResult = new byte[data.length];

        int source;
        for(source = 0; source < height; ++source) {
            for(int bitmap = 0; bitmap < width; ++bitmap) {
                rawResult[bitmap * height + height - source - 1] = data[bitmap + source * width];
            }
        }

        source = width;
        width = height;
        height = source;
        data = rawResult;
    }

    Result var20 = null;
    PlanarYUVLuminanceSource var21 = this.buildLuminanceSource(data, width, height);
    if(var21 != null) {
        BinaryBitmap var22 = new BinaryBitmap(new HybridBinarizer(var21));

        try {
            var20 = this.mMultiFormatReader.decodeWithState(var22);
        } catch (ReaderException var16) {
            ;
        } catch (NullPointerException var17) {
            ;
        } catch (ArrayIndexOutOfBoundsException var18) {
            ;
        } finally {
            this.mMultiFormatReader.reset();
        }
    }

    if(var20 != null) {
        this.stopCamera();
        if(this.mResultHandler != null) {
            this.mResultHandler.handleResult(var20);
        }
    } else {
        camera.setOneShotPreviewCallback(this);
    }

}
 
Example 6
Source File: CameraManager.java    From qrcode_android with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 7
Source File: CameraManager.java    From SimplifyReader with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 8
Source File: CameraManager.java    From ScanZxing with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 * 
 * @param handler
 *            The handler to send the message to.
 * @param message
 *            The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
	Camera theCamera = camera;
	if (theCamera != null && previewing) {
		previewCallback.setHandler(handler, message);
		theCamera.setOneShotPreviewCallback(previewCallback);
	}
}
 
Example 9
Source File: CameraManager.java    From ZXingProject with MIT License 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 * 
 * @param handler
 *            The handler to send the message to.
 * @param message
 *            The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
	Camera theCamera = camera;
	if (theCamera != null && previewing) {
		previewCallback.setHandler(handler, message);
		theCamera.setOneShotPreviewCallback(previewCallback);
	}
}
 
Example 10
Source File: CameraManager.java    From AndroidHttpCapture with MIT License 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 11
Source File: CameraManager.java    From Gizwits-SmartBuld_Android with MIT License 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 * 
 * @param handler
 *            The handler to send the message to.
 * @param message
 *            The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
	Camera theCamera = camera;
	if (theCamera != null && previewing) {
		previewCallback.setHandler(handler, message);
		theCamera.setOneShotPreviewCallback(previewCallback);
	}
}
 
Example 12
Source File: CameraManager.java    From zxingfragmentlib with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
  Camera theCamera = camera;
  if (theCamera != null && previewing) {
    previewCallback.setHandler(handler, message);
    theCamera.setOneShotPreviewCallback(previewCallback);
  }
}
 
Example 13
Source File: CameraManager.java    From AndroidWebServ with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 14
Source File: CameraManager.java    From reacteu-app with MIT License 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
  Camera theCamera = camera;
  if (theCamera != null && previewing) {
    previewCallback.setHandler(handler, message);
    theCamera.setOneShotPreviewCallback(previewCallback);
  }
}
 
Example 15
Source File: CameraManager.java    From ZXing-Orient with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data will arrive as byte[]
 * in the message.obj field, with width and height encoded as message.arg1 and message.arg2,
 * respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
  Camera theCamera = camera;
  if (theCamera != null && previewing) {
    previewCallback.setHandler(handler, message);
    theCamera.setOneShotPreviewCallback(previewCallback);
  }
}
 
Example 16
Source File: CameraManager.java    From myapplication with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}
 
Example 17
Source File: CameraManager.java    From Viewer with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the supplied callback.
 *
 * The thread on which this called is undefined, so a Handler should be used to post the result
 * to the correct thread.
 *
 * @param callback The callback to receive the preview.
 */
public void requestPreviewFrame(PreviewCallback callback) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        cameraPreviewCallback.setCallback(callback);
        theCamera.setOneShotPreviewCallback(cameraPreviewCallback);
    }
}
 
Example 18
Source File: CameraManager.java    From BarcodeScanner with Apache License 2.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively. <br/>
 * 
 * 两个绑定操作:<br/>
 * 1:将handler与回调函数绑定;<br/>
 * 2:将相机与回调函数绑定<br/>
 * 综上,该函数的作用是当相机的预览界面准备就绪后就会调用hander向其发送传入的message
 * 
 * @param handler
 *            The handler to send the message to.
 * @param message
 *            The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
	Camera theCamera = camera;
	if (theCamera != null && previewing) {
		previewCallback.setHandler(handler, message);

		// 绑定相机回调函数,当预览界面准备就绪后会回调Camera.PreviewCallback.onPreviewFrame
		theCamera.setOneShotPreviewCallback(previewCallback);
	}
}
 
Example 19
Source File: CameraManager.java    From GOpenSource_AppKit_Android_AS with MIT License 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 * 
 * @param handler
 *            The handler to send the message to.
 * @param message
 *            The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
	Camera theCamera = camera;
	if (theCamera != null && previewing) {
		previewCallback.setHandler(handler, message);
		theCamera.setOneShotPreviewCallback(previewCallback);
	}
}
 
Example 20
Source File: CameraManager.java    From AirFree-Client with GNU General Public License v3.0 3 votes vote down vote up
/**
 * A single preview frame will be returned to the handler supplied. The data
 * will arrive as byte[] in the message.obj field, with width and height
 * encoded as message.arg1 and message.arg2, respectively.
 *
 * @param handler The handler to send the message to.
 * @param message The what field of the message to be sent.
 */
public synchronized void requestPreviewFrame(Handler handler, int message) {
    Camera theCamera = camera;
    if (theCamera != null && previewing) {
        previewCallback.setHandler(handler, message);
        theCamera.setOneShotPreviewCallback(previewCallback);
    }
}