【问题标题】:How to showing android camera simply [closed]如何简单地显示android相机[关闭]
【发布时间】:2014-09-11 07:56:49
【问题描述】:

我需要一些示例代码来显示相机而不拍照。 最简单的方法是什么?

【问题讨论】:

    标签: android camera


    【解决方案1】:

    在您的 AndroidManifest.xml 中:

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera" />
    

    在您的代码中:

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    
    startActivityForResult(cameraIntent, CAMERA_REQUEST);
    

    【讨论】:

      【解决方案2】:

      使用此代码作为示例:打开相机

      public void open(){
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 0);
      }
      

      捕获图像:

       protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        Bitmap bp = (Bitmap) data.getExtras().get("data");
        imgFavorite.setImageBitmap(bp);
      }
      

      在 Manifest 中添加权限:

      <uses-permission android:name="android.permission.CAMERA"/>
      <uses-feature android:name="android.hardware.camera" />
      

      XML:

      内部相对布局采用 Imageview 和 textview

      试试这个。

      【讨论】:

        【解决方案3】:

        此链接将比我更好地解释所有内容:http://developer.android.com/guide/topics/media/camera.html

        【讨论】:

        【解决方案4】:
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
        startActivityForResult(cameraIntent, CAMERA_REQUEST); 
        

        【讨论】:

          猜你喜欢
          • 2021-12-20
          • 1970-01-01
          • 1970-01-01
          • 2011-01-23
          • 2011-08-10
          • 1970-01-01
          • 1970-01-01
          • 2017-01-21
          • 1970-01-01
          相关资源
          最近更新 更多