第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何正確設(shè)置Android相機(jī)方向?

如何正確設(shè)置Android相機(jī)方向?

素胚勾勒不出你 2019-08-16 17:25:58
如何正確設(shè)置Android相機(jī)方向?我想根據(jù)Android中的設(shè)備方向設(shè)置相機(jī)方向,但似乎沒有任何效果。我嘗試旋轉(zhuǎn)Surface以及相機(jī)參數(shù),但是縱向模式下的相機(jī)預(yù)覽總是顛倒過來。我需要順時(shí)針旋轉(zhuǎn)90度才能使其正確。這是我現(xiàn)在使用的代碼,僅適用于橫向模式。    SurfaceHolder.Callback surfaceCallback = new SurfaceHolder.Callback() {     @Override     public void surfaceDestroyed(SurfaceHolder holder) {         camera.stopPreview();         camera.release();         camera = null;     }     @Override     public void surfaceCreated(SurfaceHolder holder) {                   initCamera();                }     private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {         final double ASPECT_TOLERANCE = 0.2;         double targetRatio = (double) w / h;         if (sizes == null)             return null;         Size optimalSize = null;         double minDiff = Double.MAX_VALUE;         int targetHeight = h;         // Try to find an size match aspect ratio and size         for (Size size : sizes) {             Log.d(TAG, "Checking size " + size.width + "w " + size.height                    + "h");             double ratio = (double) size.width / size.height;             if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)                 continue;             if (Math.abs(size.height - targetHeight) < minDiff) {                 optimalSize = size;                 minDiff = Math.abs(size.height - targetHeight);             }         }         // Cannot find the one match the aspect ratio, ignore the         // requirement         if (optimalSize == null) {             minDiff = Double.MAX_VALUE;             for (Size size : sizes) {                 if (Math.abs(size.height - targetHeight) < minDiff) {                     optimalSize = size;                     minDiff = Math.abs(size.height - targetHeight);                 }             }         }         return optimalSize;     }
查看完整描述

3 回答

?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

此解決方案適用于所有 Android版本。您可以在Java中使用反射使其適用于所有Android設(shè)備:

基本上你應(yīng)該創(chuàng)建一個(gè)反射包裝來調(diào)用Android 2.2 setDisplayOrientation,而不是調(diào)用特定的方法。

方法:

    protected void setDisplayOrientation(Camera camera, int angle){
    Method downPolymorphic;
    try
    {
        downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
        if (downPolymorphic != null)
            downPolymorphic.invoke(camera, new Object[] { angle });
    }
    catch (Exception e1)
    {
    }}

而不是使用camera.setDisplayOrientation(x)使用setDisplayOrientation(camera,x)

    if (Integer.parseInt(Build.VERSION.SDK) >= 8)
        setDisplayOrientation(mCamera, 90);
    else
    {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {
            p.set("orientation", "portrait");
            p.set("rotation", 90);
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            p.set("orientation", "landscape");
            p.set("rotation", 90);
        }
    }


查看完整回答
反對(duì) 回復(fù) 2019-08-16
  • 3 回答
  • 0 關(guān)注
  • 1414 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)