getBestSupportedSize


#1

/** a simple algorithm to get the largest size available. For a more * robust version, see CameraPreview.java in the ApiDemos * sample app from Android. */ private Size getBestSupportedSize(List<Size> sizes, int width, int height) { Size bestSize = sizes.get(0); int largestArea = bestSize.width * bestSize.height; for (Size s : sizes) { int area = s.width * s.height; if (area > largestArea) { bestSize = s; largestArea = area; } } return bestSize; }

I thought the width and height parameters were needed to get the biggest size available constrained by width and height? They don’t appear to be used in the determination? Thanks!


#2

You’re right - our code is extremely simple, and doesn’t use them. In a more sophisticated implementation, you would.

In the next edition, we will probably leave those parameters out.


#3

What if you were to perform the following additional check:

private Size getBestSupportedSize(List<Size> sizes, int width, int height){
	Size bestSize = sizes.get(0);
	long largestArea = bestSize.width * bestSize.height;
	for (Size s: sizes){
		long area = s.width * s.height;
		[color=#FF0000]if(area > largestArea && s.width <= width && s.height <= height){[/color]
			bestSize = s;
			largestArea = area;
		}
		
	}
	return bestSize;
}

Will that suffice?