gpt4 book ai didi

java - 如何在 Android Studio Camera2 中找到相机百万像素

转载 作者:行者123 更新时间:2023-12-01 18:44:42 24 4
gpt4 key购买 nike

我需要获得百万像素的设备摄像头,但我不知道该怎么做。我想使用 textView,以便可以在应用程序上显示它。

最佳答案

您可以使用这段代码获得百万像素:

    public void getCamerasMegaPixel() {
Camera camera = Camera.open(0); // For Back Camera
android.hardware.Camera.Parameters params = camera.getParameters();
List supportedPictureSizes = params.getSupportedPictureSizes();
Camera.Size result = null;

ArrayList<Integer> widthList = new ArrayList<Integer>();
ArrayList<Integer> heightList = new ArrayList<Integer>();

for (int i = 0; i < supportedPictureSizes.size(); i++) {
result = (Camera.Size) supportedPictureSizes.get(i);
widthList.add(result.width);
heightList.add(result.height);
}
if (widthList.size() != 0 && heightList.size() != 0) {
System.out.println("Back Megapixel :" + calculateMegaPixel(widthList, heightList));
}
camera.release();

widthList.clear();
heightList.clear();

camera = Camera.open(1); // For Front Camera
android.hardware.Camera.Parameters params1 = camera.getParameters();
List sizes1 = params1.getSupportedPictureSizes();
Camera.Size result1 = null;
for (int i = 0; i < sizes1.size(); i++) {
result1 = (Camera.Size) sizes1.get(i);
widthList.add(result1.width);
heightList.add(result1.height);
}
if (widthList.size() != 0 && heightList.size() != 0) {
System.out.println("FRONT Megapixel :" + calculateMegaPixel(widthList, heightList));
}

camera.release();
}

public float calculateMegaPixel(List<Integer> widthList, List<Integer> heightList) {
return ((Collections.max(widthList)) * (Collections.max(heightList))) / 1024000;
}

如果你想使用camera2 api,可以在这里使用:

public String getCamerasMegaPixel() throws CameraAccessException {
String output = "";
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

String[] cameraIds = manager.getCameraIdList();
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIds[0]);
output = "back camera mega pixel: " + calculateMegaPixel(characteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE).getWidth(),
characteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE).getHeight()) + "\n";

characteristics = manager.getCameraCharacteristics(cameraIds[1]);
output += "front camera mega pixel: " + calculateMegaPixel(characteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE).getWidth(),characteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE).getHeight()) + "\n";
return output;
}
public int calculateMegaPixel(float width, float height) {
return Math.round((width * height) / 1024000);
}

关于java - 如何在 Android Studio Camera2 中找到相机百万像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59862349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com