mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Set the best resolution for the picture taken.
This commit is contained in:
@@ -1017,6 +1017,20 @@ public class CameraActivity extends Activity {
|
||||
Camera.Parameters camParameters = customCamera.getParameters();
|
||||
camParameters.setPreviewSize(optimalSize.width, optimalSize.height);
|
||||
customCamera.setParameters(camParameters);
|
||||
setPictureSizeFromPreviewSize(optimalSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* To set the picture size optimized on the preview size.
|
||||
* @param Size previewSize
|
||||
*/
|
||||
private void setPictureSizeFromPreviewSize(Size previewSize) {
|
||||
Size optimalPictureSize = ManagerCamera.getOptimalPictureSize(previewSize.width, previewSize.height);
|
||||
if (optimalPictureSize != null) {
|
||||
Camera.Parameters camParameters = customCamera.getParameters();
|
||||
camParameters.setPictureSize(optimalPictureSize.width, optimalPictureSize.height);
|
||||
customCamera.setParameters(camParameters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -240,6 +240,38 @@ public class ManagerCamera {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return optimalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the optimal picture size.
|
||||
*
|
||||
* @param int w Width of the wanted picture.
|
||||
* @param int h Height of the wanted picture.
|
||||
*
|
||||
* @return Camera.Size Optimal resolution.
|
||||
*/
|
||||
public static Camera.Size getOptimalPictureSize(int w, int h) {
|
||||
List<Camera.Size> pictureSizes = ManagerCamera.mCamera.getParameters().getSupportedPictureSizes();
|
||||
|
||||
if (pictureSizes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Camera.Size optimalSizePicture = null;
|
||||
for (Camera.Size size : pictureSizes) {
|
||||
if (
|
||||
((float)size.width / (float)size.height) == ((float)w / (float)h) &&
|
||||
(
|
||||
optimalSizePicture == null ||
|
||||
optimalSizePicture.width < size.width
|
||||
)
|
||||
) {
|
||||
optimalSizePicture = size;
|
||||
}
|
||||
}
|
||||
|
||||
return optimalSizePicture;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user