如何在Android系統中調用系統自拍

來源:互聯網
上載者:User

 方式是採用MediaStore,調用系統原生的相機。

12345678 Intent intent =
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra("camerasensortype",
2); // 調用自拍
intent.putExtra("autofocus",
true); // 自動對焦
intent.putExtra("fullScreen",
false);
// 全屏 intent.putExtra("showActionIcons",
false);  startActivityForResult(intent, PICK_FROM_CAMERA);

另外一種方式是採用Camera架構,以前版本的SDK裡只有Camera.open()方法來調用後置網路攝影機,現在此方法接受一個參數來確定是自拍還是後置網路攝影機。我們還根據新的Camerainfo類和getCameraInfo方法來擷取Android裝置上的詳細的網路攝影機資訊,getNumberOfCameras()來擷取網路攝影機的數量。典型的調用方式如下:

12345678910111213141516     int
cameraCount = 0;
    Camera cam =
null;        Camera.CameraInfo cameraInfo =
new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
// get cameras number                 for
( int
camIdx =
0; camIdx < cameraCount;camIdx++ ) {
        Camera.getCameraInfo( camIdx, cameraInfo );
// get camerainfo         if
( cameraInfo.facing ==Camera.CameraInfo.CAMERA_FACING_FRONT ) {
// 代表網路攝影機的方位, //目前有定義值兩個分別為CAMERA_FACING_FRONT前置和CAMERA_FACING_BACK後置
            try
{                             cam = Camera.open( camIdx );
            }
catch (RuntimeExceptione) {
                e.printStackTrace();
        }
    }

採用Camera架構的好處在於自身提供了大量的API例如 setDisplayOrientation、Camera.Parameters來實現強大的功能,另外結合 urfaceHolder.Callback、ShutterCallback和PictureCallback等介面後可以進行介面和功能的自訂,可以自由的實現所需要的介面布局和影像處理效果。例如如下的介面:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.