本文整理匯總了Java中android.hardware.Camera.Parameters.getPreviewSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Parameters.getPreviewSize方法的具體用法?Java Parameters.getPreviewSize怎麽用?Java Parameters.getPreviewSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.Camera.Parameters
的用法示例。
在下文中一共展示了Parameters.getPreviewSize方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPreviewFrame
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
public void onPreviewFrame(byte[] data, Camera camera) {
Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms) {
// scanText.setText("barcode result " + sym.getData());
Toast.makeText(MainActivity.this,sym.getData(),Toast.LENGTH_SHORT).show();
barcodeScanned = false;
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
// previewing = true;
mCamera.autoFocus(autoFocusCB);
}
}
}
示例2: logCameraParameters
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
@UiThread
private void logCameraParameters() {
if (LOG.isLoggable(INFO)) {
Parameters params = camera.getParameters();
if (Build.VERSION.SDK_INT >= 15) {
LOG.info("Video stabilisation enabled: "
+ params.getVideoStabilization());
}
LOG.info("Scene mode: " + params.getSceneMode());
LOG.info("Focus mode: " + params.getFocusMode());
LOG.info("Flash mode: " + params.getFlashMode());
Size size = params.getPreviewSize();
LOG.info("Preview size: " + size.width + "x" + size.height);
}
}
示例3: jpegFromPreview
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
byte[] jpegFromPreview(byte[] currentPreview) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Parameters parameters = mCamera.getParameters();
Size size = parameters.getPreviewSize();
YuvImage image = new YuvImage(currentPreview, parameters.getPreviewFormat(), size.width, size.height, null);
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), quality, baos);
byte[] jpeg = baos.toByteArray();
float rotation = (float) 0.;
if (cameraId == 1 && mDisplay.getRotation() == Surface.ROTATION_0)
rotation = (float) 270.;
else if (cameraId == 0 && mDisplay.getRotation() == Surface.ROTATION_0)
rotation = (float) 90.;
if (debug) Log.i(TAG, "cameraId: " + cameraId + ", getRotation: " + mDisplay.getRotation() + ", rotation: " + rotation);
if (rotation != 0.) {
// This is the same image as the preview but in JPEG and not rotated
Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
ByteArrayOutputStream rotatedStream = new ByteArrayOutputStream();
// Rotate the Bitmap
Matrix matrix = new Matrix();
matrix.postRotate(rotation);
// We rotate the same Bitmap
bitmap = Bitmap.createBitmap(bitmap, 0, 0, image.getWidth(), image.getHeight(), matrix, false);
// We dump the rotated Bitmap to the stream
bitmap.compress(CompressFormat.JPEG, 50, rotatedStream);
jpeg = rotatedStream.toByteArray();
// whew
}
return jpeg;
}
示例4: doInBackground
import android.hardware.Camera.Parameters; //導入方法依賴的package包/類
@Override
protected byte[] doInBackground(Object... objs) {
byte[] frame = (byte[]) objs[0];
Parameters parameters = (Parameters) objs[1];
if (frame_firstUpdateTime == 0) {
frame_firstUpdateTime = System.currentTimeMillis();
}
frame_currentUpdateTime = System.currentTimeMillis();
int datasize = 0;
cameraImageSize = parameters.getPreviewSize();
YuvImage image = new YuvImage(frame, parameters.getPreviewFormat(), cameraImageSize.width,
cameraImageSize.height, null);
ByteArrayOutputStream tmpBuffer = new ByteArrayOutputStream();
image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 90, tmpBuffer);
Log.d(LOG_TAG, "compression took: "
+ (System.currentTimeMillis()-frame_currentUpdateTime));
synchronized (frameLock) {
frameBuffer = tmpBuffer.toByteArray();
frameGeneratedTime = System.currentTimeMillis();
frameID++;
frameLock.notify();
}
datasize = tmpBuffer.size();
frame_count++;
frame_totalsize += datasize;
if (frame_count % 50 == 0) {
Log.d(LOG_TAG, "(IMG)\t" +
"BW: " + 8.0 * frame_totalsize / (frame_currentUpdateTime - frame_firstUpdateTime) / 1000 +
" Mbps\tCurrent FPS: " + 8.0 * datasize / (frame_currentUpdateTime - frame_prevUpdateTime) / 1000 + " Mbps\t" +
"FPS: " + 1000.0 * frame_count / (frame_currentUpdateTime - frame_firstUpdateTime));
}
frame_prevUpdateTime = frame_currentUpdateTime;
return tmpBuffer.toByteArray();
}