android.hardware.Camera#setOneShotPreviewCallback ( )源码实例Demo

下面列出了android.hardware.Camera#setOneShotPreviewCallback ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: StarBarcode   文件: CameraManager.java
/**
 * 停止预览
 */
@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();
        }
    }
}
 
源代码2 项目: ScanZbar   文件: CameraManager.java
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);
    }
}
 
源代码3 项目: FamilyChat   文件: CameraManager.java
/**
 * 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);
    }
}
 
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);
    }

}
 
源代码5 项目: smartcoins-wallet   文件: ZXingScannerView.java
@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);
    }
}
 
源代码6 项目: AirFree-Client   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码7 项目: reacteu-app   文件: CameraManager.java
/**
 * 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);
  }
}
 
源代码8 项目: zxingfragmentlib   文件: CameraManager.java
/**
 * 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);
  }
}
 
源代码9 项目: qrcode_android   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码10 项目: SimplifyReader   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码11 项目: ScanZxing   文件: CameraManager.java
/**
 * 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);
	}
}
 
源代码12 项目: ZXingProject   文件: CameraManager.java
/**
 * 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);
	}
}
 
源代码13 项目: AndroidHttpCapture   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码14 项目: Gizwits-SmartBuld_Android   文件: CameraManager.java
/**
 * 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);
	}
}
 
源代码15 项目: AndroidWebServ   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码16 项目: ZXing-Orient   文件: CameraManager.java
/**
 * 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);
  }
}
 
源代码17 项目: myapplication   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码18 项目: Viewer   文件: CameraManager.java
/**
 * 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);
    }
}
 
源代码19 项目: BarcodeScanner   文件: CameraManager.java
/**
 * 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);
	}
}
 
/**
 * 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);
	}
}