get Largest Size for a list of Camera Size - Android android.hardware

Android examples for android.hardware:Camera Size

Description

get Largest Size for a list of Camera Size

Demo Code

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.graphics.Point;
import android.hardware.Camera;

public class Main {

  private static Comparator<Camera.Size> CAMERA_SIZE_COMPARATOR = new Comparator<Camera.Size>() {
    @Override/*from  ww  w.  j  a  v  a 2s .c o  m*/
    public int compare(Camera.Size lhs, Camera.Size rhs) {
      return lhs.width * lhs.height - rhs.width * rhs.height;
    }
  };

  public static Point getLargestSize(final List<Camera.Size> list) {
    if (list == null || list.isEmpty())
      return null;
    final ArrayList<Camera.Size> sorted = new ArrayList<>(list);
    Collections.sort(sorted, CAMERA_SIZE_COMPARATOR);
    final Camera.Size size = sorted.get(sorted.size() - 1);
    return new Point(size.width, size.height);
  }

}

Related Tutorials