カメラの解像度、テクスチャ表示とデバイスの表示寸法が同じでない場合は、寸法を調整する必要があります。そのためには、TextureViewをFrameLayoutの中に入れてください。以下のコードは、さまざまなディスプレイ解像度のすべてのデバイスに適用されます。
フルスクリーンでプレビューする場合は、表示ディメンションを使用してください。int DSI_height
、int DSI_width
グローバル変数。
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
DSI_height = displayMetrics.heightPixels;
DSI_width = displayMetrics.widthPixels;
カメラ2 APIからあなたに必要な解像度を選択し、Size imageDimension
に割り当て、グローバルprivate Size imageDimension
を取り、
setAspectRatioTextureView(imageDimension.getHeight(),imageDimension.getWidth());
を使用して、論理の下に使用
private void setAspectRatioTextureView(int ResolutionWidth , int ResolutionHeight)
{
if(ResolutionWidth > ResolutionHeight){
int newWidth = DSI_width;
int newHeight = ((DSI_width * ResolutionWidth)/ResolutionHeight);
updateTextureViewSize(newWidth,newHeight);
}else {
int newWidth = DSI_width;
int newHeight = ((DSI_width * ResolutionHeight)/ResolutionWidth);
updateTextureViewSize(newWidth,newHeight);
}
}
private void updateTextureViewSize(int viewWidth, int viewHeight) {
Log.d(TAG, "TextureView Width : " + viewWidth + " TextureView Height : " + viewHeight);
textureView.setLayoutParams(new FrameLayout.LayoutParams(viewWidth, viewHeight));
}
私はいくつかのデバイスを持っていますテストのために、Googleのサンプルを使用しましたが、一部のデバイスでうまく動作しません。カメラのプレビューはまだフルスクリーンで拡大されています。しかし、私が '' 'map.getOutputSizes(SurfaceTexture.class)[0]' 'を使うと、すべてのデバイスで完全に動作します。 – TrungNVT
@ TrungNVTしかし、あなたはフルスクリーンプレビューを取得する必要はありません..右? –