Last active
December 16, 2015 11:58
-
-
Save Kozlov-V/5430727 to your computer and use it in GitHub Desktop.
Пример кода для работы с камерой. Задача этого кода, подогнать соотношение сторон окна (экрана телефона) и соотношения сторон кадра с камеры и повернуть изображение соответственно ориентации телефона.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Size previewSize = camera.getParameters().getPreviewSize(); | |
float aspect = (float) previewSize.width / previewSize.height; | |
int previewSurfaceWidth = preview.getWidth(); | |
int previewSurfaceHeight = preview.getHeight(); | |
LayoutParams lp = preview.getLayoutParams(); | |
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) | |
{ | |
// портретный вид | |
camera.setDisplayOrientation(90); | |
lp.height = previewSurfaceHeight; | |
lp.width = (int) (previewSurfaceHeight / aspect); | |
; | |
} | |
else | |
{ | |
camera.setDisplayOrientation(0); | |
lp.width = previewSurfaceWidth; | |
lp.height = (int) (previewSurfaceWidth / aspect); | |
} | |
preview.setLayoutParams(lp); | |
camera.startPreview(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment