zoukankan      html  css  js  c++  java
  • Android 调用照相机拍照

    public class MyCameraActivity extends Activity {

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button btnCamera = (Button) findViewById(R.id.btnCamera);
            btnCamera.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    letCamera();
                }
            });
        }

        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {
            case 1:// 拍照
                if (resultCode == RESULT_OK) {
                    Toast.makeText(this, "拍摄成功", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
            }
        }

        protected void letCamera() {
            // TODO Auto-generated method stub
            Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            String strImgPath = Environment.getExternalStorageDirectory()
                    .toString() + "/dlion/";// 存放照片的文件夹
            String fileName = new SimpleDateFormat("yyyyMMddHHmmss")
                    .format(new Date()) + ".jpg";// 照片命名
            File out = new File(strImgPath);
            if (!out.exists()) {
                out.mkdirs();
            }
            out = new File(strImgPath, fileName);
            strImgPath = strImgPath + fileName;// 该照片的绝对路径
            Uri uri = Uri.fromFile(out);
            imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
            imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            startActivityForResult(imageCaptureIntent, 1);
        }
    }

    转自:http://www.cnblogs.com/oldfeel/archive/2012/04/26/2470864.html

  • 相关阅读:
    P2155 [SDOI2008]沙拉公主的困惑
    P4345 [SHOI2015]超能粒子炮·改
    乘法逆元
    P1608 路径统计
    P1342 请柬
    一些网址
    20/08/02测试
    ivqBlog 开源博客 (angularjs + express + mongodb)
    angularjs, nodejs, express, gulp, karma, jasmine 前端方案整合
    参照nopCommerce框架开发(NextCMS)
  • 原文地址:https://www.cnblogs.com/yiki/p/2474828.html
Copyright © 2011-2022 走看看