Example usage for android.util Size getHeight

List of usage examples for android.util Size getHeight

Introduction

In this page you can find the example usage for android.util Size getHeight.

Prototype

public int getHeight() 

Source Link

Document

Get the height of the size (in pixels).

Usage

From source file:kr.ac.kpu.wheeling.blackbox.Camera2VideoFragment.java

/**
 * Given {@code choices} of {@code Size}s supported by a camera, chooses the smallest one whose
 * width and height are at least as large as the respective requested values, and whose aspect
 * ratio matches with the specified value.
 *
 * @param choices     The list of sizes that the camera supports for the intended output class
 * @param width       The minimum desired width
 * @param height      The minimum desired height
 * @param aspectRatio The aspect ratio//w w w. j  av a 2s .  c o  m
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int width, int height, Size aspectRatio) {
    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<Size>();

    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    Log.d("INFO", "w, h: " + w + h);
    for (Size option : choices) {
        Log.d("SIZE", "option Width= " + option.getWidth() + " option Height= " + option.getHeight());
        if (option.getHeight() == option.getWidth() * h / w && option.getWidth() >= w
                && option.getHeight() >= h) {
            Log.d("SELECTED SIZE",
                    "option Width= " + option.getWidth() + " option Height= " + option.getHeight());
            bigEnough.add(option);
        }
    }

    // Pick the smallest of those, assuming we found any
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        return choices[0];
    }
}

From source file:org.odk.collect.android.fragments.Camera2Fragment.java

/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class/*from  ww  w  .  j  a  va2 s. c o  m*/
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @param aspectRatio       The aspect ratio
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth,
        int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight
                && option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        return choices[0];
    }
}

From source file:camera2basic.Camera2BasicFragment.java

/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class//  www  .  jav  a2 s. c  om
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @param aspectRatio       The aspect ratio
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth,
        int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight
                && option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        return choices[0];
    }
}

From source file:com.example.joshf.conc.CameraFragment.java

private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth,
        int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight
                && option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);//from w w w . ja  v a  2 s . com
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        return choices[0];
    }
}

From source file:com.visualnavigate.CameraFragment.java

/**
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class/*w w  w . j  a  v a2  s.c  o  m*/
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @param aspectRatio       The aspect ratio
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth,
        int maxHeight, Size aspectRatio) {

    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight
                && option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }

    // Pick the largest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.max(bigEnough, new CompareSizesByArea());
        //} else if (notBigEnough.size() > 0) {
        //    return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        //httpHelper.logRequest("error", "Couldn't find any suitable preview size", this.getActivity());
        return choices[0];
    }
}

From source file:com.dastanapps.camera2.view.Cam2AutoFitTextureView.java

protected void touchToFocus(MotionEvent event) {
    //first stop the existing repeating request
    try {/*from  ww w .jav  a  2s .co m*/
        mPreviewSession.stopRepeating();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    Rect rect = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    Log.i(TAG, "SENSOR_INFO_ACTIVE_ARRAY_SIZE,,,,,,,,rect.left--->" + rect.left + ",,,rect.top--->" + rect.top
            + ",,,,rect.right--->" + rect.right + ",,,,rect.bottom---->" + rect.bottom);
    Size size = mCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
    Log.i(TAG, "mCameraCharacteristics,,,,size.getWidth()--->" + size.getWidth() + ",,,size.getHeight()--->"
            + size.getHeight());
    int areaSize = 200;
    int right = rect.right;
    int bottom = rect.bottom;
    int viewWidth = getWidth();
    int viewHeight = getHeight();
    int ll, rr;
    Rect newRect;
    int centerX = (int) event.getX();
    int centerY = (int) event.getY();
    ll = ((centerX * right) - areaSize) / viewWidth;
    rr = ((centerY * bottom) - areaSize) / viewHeight;
    int focusLeft = clamp(ll, 0, right);
    int focusBottom = clamp(rr, 0, bottom);
    Log.i(TAG, "focusLeft--->" + focusLeft + ",,,focusTop--->" + focusBottom + ",,,focusRight--->"
            + (focusLeft + areaSize) + ",,,focusBottom--->" + (focusBottom + areaSize));
    newRect = new Rect(focusLeft, focusBottom, focusLeft + areaSize, focusBottom + areaSize);
    MeteringRectangle meteringRectangle = new MeteringRectangle(newRect, 500);
    MeteringRectangle[] meteringRectangleArr = { meteringRectangle };
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, meteringRectangleArr);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
}

From source file:MainActivity.java

protected void takePicture(View view) {
    if (null == mCameraDevice) {
        return;/*from w ww.  jav a2 s  .c  om*/
    }
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId());
        StreamConfigurationMap configurationMap = characteristics
                .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (configurationMap == null)
            return;
        Size largest = Collections.max(Arrays.asList(configurationMap.getOutputSizes(ImageFormat.JPEG)),
                new CompareSizesByArea());
        ImageReader reader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG,
                1);
        List<Surface> outputSurfaces = new ArrayList<Surface>(2);
        outputSurfaces.add(reader.getSurface());
        outputSurfaces.add(new Surface(mTextureView.getSurfaceTexture()));
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(reader.getSurface());
        captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                Image image = null;
                try {
                    image = reader.acquireLatestImage();
                    ByteBuffer buffer = image.getPlanes()[0].getBuffer();
                    byte[] bytes = new byte[buffer.capacity()];
                    buffer.get(bytes);
                    OutputStream output = new FileOutputStream(getPictureFile());
                    output.write(bytes);
                    output.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (image != null) {
                        image.close();
                    }
                }
            }
        };
        HandlerThread thread = new HandlerThread("CameraPicture");
        thread.start();
        final Handler backgroudHandler = new Handler(thread.getLooper());
        reader.setOnImageAvailableListener(readerListener, backgroudHandler);
        final CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                    TotalCaptureResult result) {
                super.onCaptureCompleted(session, request, result);
                Toast.makeText(MainActivity.this, "Picture Saved", Toast.LENGTH_SHORT).show();
                startPreview(session);
            }
        };
        mCameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(CameraCaptureSession session) {
                try {
                    session.capture(captureBuilder.build(), captureCallback, backgroudHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(CameraCaptureSession session) {
            }
        }, backgroudHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:java_lang_programming.com.android_media_demo.article94.java.ImageDecoderActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case (REQUEST_CODE_CHOOSER):
        if (resultCode != RESULT_OK || data.getData() == null) {
            Toast.makeText(this, getString(R.string.image_unselected_message), Toast.LENGTH_LONG).show();
            return;
        }/*from   w  ww .  java2s  .  c  o  m*/
        Bitmap bitmap = null;
        // P ?
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1) {
            Log.d("ImageDecoderActivity", "ImageDecoder");
            StringBuilder msg = new StringBuilder();
            try {
                //                        bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(getContentResolver(), data.getData()));
                bitmap = ImageDecoder.decodeBitmap(
                        ImageDecoder.createSource(getContentResolver(), data.getData()),
                        new ImageDecoder.OnHeaderDecodedListener() {
                            @Override
                            public void onHeaderDecoded(ImageDecoder imageDecoder,
                                    ImageDecoder.ImageInfo imageInfo, ImageDecoder.Source source) {
                                if (checkedResize.isChecked()) {
                                    Size size = imageInfo.getSize();
                                    imageDecoder.setResize(size.getWidth() * 2, size.getHeight() * 2);
                                }

                                if (checkedCrop.isChecked()) {
                                    Size size = imageInfo.getSize();
                                    imageDecoder.setCrop(new Rect(0, 0, size.getWidth(), size.getHeight() / 2));
                                }

                                msg.append("ImageDecoder?bitmap??????\n");
                                msg.append("? : " + imageInfo.getSize() + "\n");
                                msg.append("? : " + imageInfo.getMimeType() + "\n");
                                msg.append(" : " + imageInfo.isAnimated() + "\n");
                            }
                        });
            } catch (IOException e) {
                e.printStackTrace();
            }
            selectedImageInfo.setText(msg.toString());
            // ?
        } else {
            Log.d("ImageDecoderActivity", "BitmapFactory");
            bitmap = getBitmap(getApplicationContext(), data.getData());
            selectedImageInfo.setText("BitmapFactory?bitmap??????");
        }

        if (bitmap != null) {
            selectedImage.setImageBitmap(bitmap);
        }
        break;
    default:
        break;
    }
}

From source file:com.example.camera2apidemo.Camera2BasicFragment.java

/**
 * ?// w  w w .j  a  v  a 2s  . c o m
 * @param choices           ?list
 * @param textureViewWidth  texture view 
 * @param textureViewHeight texture view 
 * @param maxWidth          
 * @param maxHeight         
 * @param aspectRatio       ?(pictureSize, ?pictureSizetextureSize??, ??)
 * @return ?
 * Given {@code choices} of {@code Size}s supported by a camera, choose the smallest one that
 * is at least as large as the respective texture view size, and that is at most as large as the
 * respective max size, and whose aspect ratio matches with the specified value. If such size
 * doesn't exist, choose the largest one that is at most as large as the respective max size,
 * and whose aspect ratio matches with the specified value.
 *
 * @param choices           The list of sizes that the camera supports for the intended output
 *                          class
 * @param textureViewWidth  The width of the texture view relative to sensor coordinate
 * @param textureViewHeight The height of the texture view relative to sensor coordinate
 * @param maxWidth          The maximum width that can be chosen
 * @param maxHeight         The maximum height that can be chosen
 * @param aspectRatio       The aspect ratio
 * @return The optimal {@code Size}, or an arbitrary one if none were big enough
 */
private static Size chooseOptimalSize(Size[] choices, int textureViewWidth, int textureViewHeight, int maxWidth,
        int maxHeight, Size aspectRatio) {
    // ??, textureSize
    // Collect the supported resolutions that are at least as big as the preview Surface
    List<Size> bigEnough = new ArrayList<>();
    // ??, ?textureSize
    // Collect the supported resolutions that are smaller than the preview Surface
    List<Size> notBigEnough = new ArrayList<>();
    int w = aspectRatio.getWidth();
    int h = aspectRatio.getHeight();
    for (Size option : choices) {
        if (option.getWidth() <= maxWidth && option.getHeight() <= maxHeight
                && option.getHeight() == option.getWidth() * h / w) {
            if (option.getWidth() >= textureViewWidth && option.getHeight() >= textureViewHeight) {
                bigEnough.add(option);
            } else {
                notBigEnough.add(option);
            }
        }
    }
    // 1. bigEnough?, ??
    // 2. ?bigEnough?, notBigEnough?, ??
    // 3. ??, , ?
    // Pick the smallest of those big enough. If there is no one big enough, pick the
    // largest of those not big enough.
    if (bigEnough.size() > 0) {
        return Collections.min(bigEnough, new CompareSizesByArea());
    } else if (notBigEnough.size() > 0) {
        return Collections.max(notBigEnough, new CompareSizesByArea());
    } else {
        Log.e(TAG, "Couldn't find any suitable preview size");
        return choices[0];
    }
}

From source file:com.example.android.hdrviewfinder.HdrViewfinderActivity.java

/**
 * Configure the surfaceview and RS processing.
 *//*from   ww  w.  j  av  a 2 s  .  com*/
private void configureSurfaces() {
    // Find a good size for output - largest 16:9 aspect ratio that's less than 720p
    final int MAX_WIDTH = 1280;
    final float TARGET_ASPECT = 16.f / 9.f;
    final float ASPECT_TOLERANCE = 0.1f;

    StreamConfigurationMap configs = mCameraInfo.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

    Size[] outputSizes = configs.getOutputSizes(SurfaceHolder.class);

    Size outputSize = outputSizes[0];
    float outputAspect = (float) outputSize.getWidth() / outputSize.getHeight();
    for (Size candidateSize : outputSizes) {
        if (candidateSize.getWidth() > MAX_WIDTH)
            continue;
        float candidateAspect = (float) candidateSize.getWidth() / candidateSize.getHeight();
        boolean goodCandidateAspect = Math.abs(candidateAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
        boolean goodOutputAspect = Math.abs(outputAspect - TARGET_ASPECT) < ASPECT_TOLERANCE;
        if ((goodCandidateAspect && !goodOutputAspect) || candidateSize.getWidth() > outputSize.getWidth()) {
            outputSize = candidateSize;
            outputAspect = candidateAspect;
        }
    }
    Log.i(TAG, "Resolution chosen: " + outputSize);

    // Configure processing
    mProcessor = new ViewfinderProcessor(mRS, outputSize);
    setupProcessor();

    // Configure the output view - this will fire surfaceChanged
    mPreviewView.setAspectRatio(outputAspect);
    mPreviewView.getHolder().setFixedSize(outputSize.getWidth(), outputSize.getHeight());
}