Android camera2api preview size stretches -
i m trying recording using camera2 api in android , my preview size stretches.
can me why preview stretches
here code:
private void setupcamera(int width, int height) { cameramanager = (cameramanager) getsystemservice(context.camera_service); try { (string camid : cameramanager.getcameraidlist()) { cameracharacteristics = cameramanager.getcameracharacteristics(camid); if (cameracharacteristics.get(cameracharacteristics.lens_facing) == cameracharacteristics.lens_facing_front) { continue; } streamconfigurationmap map = cameracharacteristics.get(cameracharacteristics.scaler_stream_configuration_map); //handling rotation of screen int deviceorientation = getwindowmanager().getdefaultdisplay().getrotation(); totalrotation = devicerotation(cameracharacteristics, deviceorientation); boolean swaprotation = totalrotation == 90 || totalrotation == 270; int rotatedwidth = height; int rotatedheigth = width; if (swaprotation) { rotatedwidth = width; rotatedheigth = height; } mpreviewsize = chooseoptimalsize(map.getoutputsizes(surfacetexture.class), rotatedwidth, rotatedheigth); mvideosize = chooseoptimalsize(map.getoutputsizes(mediarecorder.class), rotatedwidth, rotatedheigth); mcamid = camid; return; } } catch (cameraaccessexception e) { e.printstacktrace(); } } private static size chooseoptimalsize(size[] choices, int width, int height) { list<size> bigenough = new arraylist<size>(); (size option : choices) { if (option.getheight() == option.getwidth() * height / width && option.getwidth() >= width && option.getheight() >= height) { bigenough.add(option); } } if (bigenough.size() > 0) { return collections.min(bigenough, new comparesizebyarea()); } else { return choices[0]; } }
private static class comparesizebyarea implements comparator {
@override public int compare(size lhs, size rhs) { return long.signum((long) lhs.getwidth() * rhs.getheight() / (long) rhs.getwidth() * lhs.getheight()); } }
Comments
Post a Comment