Android examples for Graphics:Image Size
From the list of image sizes, select the one which is closest to the specified size.
//package com.java2s; import android.hardware.Camera; import java.util.List; public class Main { /**//w ww .j a va2s . c o m * From the list of image sizes, select the one which is closest to the specified size. */ public static int closest(List<Camera.Size> sizes, int width, int height) { int best = -1; int bestScore = Integer.MAX_VALUE; for (int i = 0; i < sizes.size(); i++) { Camera.Size s = sizes.get(i); int dx = s.width - width; int dy = s.height - height; int score = dx * dx + dy * dy; if (score < bestScore) { best = i; bestScore = score; } } return best; } }