我目前正在使用 camera2 API 制作我的 android 應(yīng)用程序。我能夠制作圖像,保存它們,編輯它們等等。但是我的相機(jī)總是被拉長。我使用的是三星 Galaxy Tab A 和三星 Galaxy Note 8,所以不是 16:9 的比例。首先,我只在橫向模式下拍照。我的textureView與我的顯示器的大小完全相同。我的預(yù)覽應(yīng)該更好,因?yàn)槲乙彩褂盟拇笮肀4鎴D像。但如果將其設(shè)置為與我的顯示器相同的尺寸,我會(huì)得到拉伸圖像。 //getting the ratio, correct setting of sizes if (verh == sechzehnzuneun) { newSize = new Size(2300, 1350); } else if (verh == sechzehnzuzehn) { newSize = new Size(2400, 1500); } else if (verh == note8) { newSize = new Size(2792, 1440); }//also used for saving _imageDimension = newSize; //used for rotating the preview, otherwise i geht some strange portrait camera Matrix matrix = new Matrix(); int rotation = getWindowManager().getDefaultDisplay().getRotation(); RectF textureRectF = new RectF(0, 0, _textureView.getWidth(), _textureView.getHeight()); RectF previewRectF = new RectF(0, 0, _imageDimension.getHeight(), _imageDimension.getWidth()); float centerX = textureRectF.centerX(); float centerY = textureRectF.centerY(); if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { previewRectF.offset(centerX - previewRectF.centerX(), centerY - previewRectF.centerY()); matrix.setRectToRect(textureRectF, previewRectF, Matrix.ScaleToFit.FILL); float scale = Math.max((float) width / _imageDimension.getWidth(), (float) height / _imageDimension.getHeight()); matrix.postScale(scale, scale, centerX, centerY); matrix.postRotate(90 * (rotation - 2), centerX, centerY); } 我得到了上層代碼的 if 情況。但是看(只看縱向,但沒有方向變化,總是水平的)
1 回答

慕姐4208626
TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
你看在AutoFitTextureView從谷歌樣品camera2應(yīng)用程序?
沒有特別保證相機(jī)設(shè)備完全支持設(shè)備的顯示尺寸,如果不支持,則選擇接近請(qǐng)求尺寸的尺寸。但這可能不會(huì)具有相同的縱橫比。
您需要選擇相機(jī)設(shè)備實(shí)際支持的尺寸,然后將 TextureView 設(shè)置為匹配的縱橫比。
添加回答
舉報(bào)
0/150
提交
取消