Zoom and use subset of larger preview

This commit is contained in:
Sean Owen 2014-04-30 23:43:06 +01:00
parent d5852ff9ef
commit 9b2ddac3cf
2 changed files with 18 additions and 6 deletions

View file

@ -25,15 +25,14 @@ import com.google.zxing.client.android.camera.CameraConfigurationUtils;
*/
final class CameraConfigurationManager {
static final int ZOOM = 2;
private CameraConfigurationManager() {
}
static void configure(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
//parameters.setPreviewSize(1024, 768);
parameters.setPreviewSize(1024, 576);
// parameters.setPreviewSize(512, 288);
parameters.setPreviewSize(1280, 720);
configureAdvanced(parameters);
camera.setParameters(parameters);
}
@ -43,7 +42,7 @@ final class CameraConfigurationManager {
CameraConfigurationUtils.setBarcodeSceneMode(parameters);
CameraConfigurationUtils.setVideoStabilization(parameters);
CameraConfigurationUtils.setMetering(parameters);
CameraConfigurationUtils.setZoom(parameters, 2.0);
CameraConfigurationUtils.setZoom(parameters, ZOOM);
}
}

View file

@ -141,8 +141,19 @@ final class DecodeRunnable implements Runnable, Camera.PreviewCallback {
private void decode(byte[] data) {
Result rawResult = null;
int subtendedWidth = width / CameraConfigurationManager.ZOOM;
int subtendedHeight = height / CameraConfigurationManager.ZOOM;
int excessWidth = width - subtendedWidth;
int excessHeight = height - subtendedHeight;
//long start = System.currentTimeMillis();
PlanarYUVLuminanceSource source =
new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
new PlanarYUVLuminanceSource(data,
width, height,
excessWidth / 2, excessHeight / 2,
subtendedWidth, subtendedHeight,
false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = new MultiFormatReader().decode(bitmap, hints);
@ -150,6 +161,8 @@ final class DecodeRunnable implements Runnable, Camera.PreviewCallback {
// continue
}
//long end = System.currentTimeMillis();
//Log.i(TAG, "Decode in " + (end - start));
Handler handler = getHandler();
Message message;
if (rawResult == null) {