Search in sources :

Example 1 with Size

use of android.hardware.Camera.Size in project UltimateAndroid by cymcsg.

the class CameraPreviewInput method setRenderSizeToCameraSize.

private void setRenderSizeToCameraSize() {
    Parameters params = camera.getParameters();
    Size previewSize = params.getPreviewSize();
    setRenderSize(previewSize.width, previewSize.height);
}
Also used : Parameters(android.hardware.Camera.Parameters) Size(android.hardware.Camera.Size)

Example 2 with Size

use of android.hardware.Camera.Size in project UltimateAndroid by cymcsg.

the class CameraPreviewInput method setRenderSizeToCameraSize.

private void setRenderSizeToCameraSize() {
    Parameters params = camera.getParameters();
    Size previewSize = params.getPreviewSize();
    setRenderSize(previewSize.width, previewSize.height);
}
Also used : Parameters(android.hardware.Camera.Parameters) Size(android.hardware.Camera.Size)

Example 3 with Size

use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.

the class CameraUtils method getPreferredPreviewSize.

/*
   * modified from: https://github.com/commonsguy/cwac-camera/blob/master/camera/src/com/commonsware/cwac/camera/CameraUtils.java
   */
@Nullable
public static Size getPreferredPreviewSize(int displayOrientation, int width, int height, @NonNull Parameters parameters) {
    final int targetWidth = displayOrientation % 180 == 90 ? height : width;
    final int targetHeight = displayOrientation % 180 == 90 ? width : height;
    final double targetRatio = (double) targetWidth / targetHeight;
    Log.w(TAG, String.format("getPreferredPreviewSize(%d, %d, %d) -> target %dx%d, AR %.02f", displayOrientation, width, height, targetWidth, targetHeight, targetRatio));
    List<Size> sizes = parameters.getSupportedPreviewSizes();
    List<Size> ideals = new LinkedList<>();
    List<Size> bigEnough = new LinkedList<>();
    for (Size size : sizes) {
        Log.w(TAG, String.format("  %dx%d (%.02f)", size.width, size.height, (float) size.width / size.height));
        if (size.height == size.width * targetRatio && size.height >= targetHeight && size.width >= targetWidth) {
            ideals.add(size);
            Log.w(TAG, "    (ideal ratio)");
        } else if (size.width >= targetWidth && size.height >= targetHeight) {
            bigEnough.add(size);
            Log.w(TAG, "    (good size, suboptimal ratio)");
        }
    }
    if (!ideals.isEmpty())
        return Collections.min(ideals, new AreaComparator());
    else if (!bigEnough.isEmpty())
        return Collections.min(bigEnough, new AspectRatioComparator(targetRatio));
    else
        return Collections.max(sizes, new AreaComparator());
}
Also used : Size(android.hardware.Camera.Size) LinkedList(java.util.LinkedList) Nullable(android.support.annotation.Nullable)

Example 4 with Size

use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.

the class CameraView method startPreview.

private void startPreview(@NonNull final Parameters parameters) {
    if (this.camera.isPresent()) {
        try {
            final Camera camera = this.camera.get();
            final Size preferredPreviewSize = getPreferredPreviewSize(parameters);
            if (preferredPreviewSize != null && !parameters.getPreviewSize().equals(preferredPreviewSize)) {
                Log.w(TAG, "starting preview with size " + preferredPreviewSize.width + "x" + preferredPreviewSize.height);
                if (state == State.ACTIVE)
                    stopPreview();
                previewSize = preferredPreviewSize;
                parameters.setPreviewSize(preferredPreviewSize.width, preferredPreviewSize.height);
                camera.setParameters(parameters);
            } else {
                previewSize = parameters.getPreviewSize();
            }
            long previewStartMillis = System.currentTimeMillis();
            camera.startPreview();
            Log.w(TAG, "camera.startPreview() -> " + (System.currentTimeMillis() - previewStartMillis) + "ms");
            state = State.ACTIVE;
            Util.runOnMain(new Runnable() {

                @Override
                public void run() {
                    requestLayout();
                    for (CameraViewListener listener : listeners) {
                        listener.onCameraStart();
                    }
                }
            });
        } catch (Exception e) {
            Log.w(TAG, e);
        }
    }
}
Also used : Size(android.hardware.Camera.Size) Camera(android.hardware.Camera) IOException(java.io.IOException)

Example 5 with Size

use of android.hardware.Camera.Size in project Signal-Android by WhisperSystems.

the class CameraView method setPreviewCallback.

public void setPreviewCallback(@NonNull final PreviewCallback previewCallback) {
    enqueueTask(new PostInitializationTask<Void>() {

        @Override
        protected void onPostMain(Void avoid) {
            if (camera.isPresent()) {
                camera.get().setPreviewCallback(new Camera.PreviewCallback() {

                    @Override
                    public void onPreviewFrame(byte[] data, Camera camera) {
                        if (!CameraView.this.camera.isPresent()) {
                            return;
                        }
                        final int rotation = getCameraPictureOrientation();
                        final Size previewSize = camera.getParameters().getPreviewSize();
                        if (data != null) {
                            previewCallback.onPreviewFrame(new PreviewFrame(data, previewSize.width, previewSize.height, rotation));
                        }
                    }
                });
            }
        }
    });
}
Also used : Size(android.hardware.Camera.Size) Camera(android.hardware.Camera)

Aggregations

Size (android.hardware.Camera.Size)30 Parameters (android.hardware.Camera.Parameters)4 Point (android.graphics.Point)3 Camera (android.hardware.Camera)3 Uri (android.net.Uri)2 IOException (java.io.IOException)2 TargetApi (android.annotation.TargetApi)1 SharedPreferences (android.content.SharedPreferences)1 Editor (android.content.SharedPreferences.Editor)1 SurfaceTexture (android.graphics.SurfaceTexture)1 Location (android.location.Location)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Message (android.os.Message)1 Nullable (android.support.annotation.Nullable)1 BinaryBitmap (com.google.zxing.BinaryBitmap)1 PlanarYUVLuminanceSource (com.google.zxing.PlanarYUVLuminanceSource)1 ReaderException (com.google.zxing.ReaderException)1 Result (com.google.zxing.Result)1 HybridBinarizer (com.google.zxing.common.HybridBinarizer)1