Android SDK支持操作Android设备内置的照相机。从Android2.3开始,支持操作多个摄像头(主要指前置摄像头和后置照相机)。通过照相机可以拍照和录像。

快速拍照(简单的拍照)直接看代码

view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="拍照"        android:id="@+id/btn"/>    <ImageView        android:layout_width="match_parent"        android:layout_height="fill_parent"        android:id="@+id/iv"/></LinearLayout>

java:

public class MainActivity extends Activity implements View.OnClickListener {    private ImageView iv=null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Button btn= (Button) findViewById(R.id.btn);        btn.setOnClickListener(this);        iv= (ImageView) findViewById(R.id.iv);    }    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        super.onActivityResult(requestCode, resultCode, data);        if(requestCode==1)        {            if(resultCode==Activity.RESULT_OK){   //判断是否点击了拍照按钮                Bitmap cameraBitmap= (Bitmap) data.getExtras().get("data");                iv.setImageBitmap(cameraBitmap);  //显示图片(没有保存到本地中)            }        }    }     @Override    public void onClick(View v) {        Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//只需这两行代码就可以调用相机        startActivityForResult(intent, 1);    }}

录视频和上方一样

Demo代码:http://download.csdn.net/detail/agonie201218/8655089


更多相关文章

  1. Android多媒体框架初步分析
  2. Android设置透明、半透明等效果
  3. android设置屏幕禁止休眠的方法
  4. android中LayoutInflater的使用
  5. android安装包apk文件反编译代码
  6. 安装、验证、优化APK
  7. Android(安卓)源代码在线查看(转)
  8. 史上最详细的Android(安卓)Studio系列教程三--快捷键
  9. Android中获取网页表单中的数据实现思路及代码

随机推荐

  1. Android上的磁盘加密(/data)
  2. Android(安卓)Studio 修改api level
  3. android获取手机已经安装的app信息
  4. (android 关机/重启)Android关机/重启流程
  5. Android(安卓)AudioManager修改设备默认
  6. Android面试-基础知识
  7. Android系统设置选项的包名
  8. Android手势滑动Tab
  9. Android(安卓)删除SD卡文件和文件及创建
  10. random.nextInt() random.nextDouble()