调用系统相机,并实现连续拍照功能。

private void intoPhotos() {
    File mediaStorageDir = new File(FileUtil.getPathRoot()+"/ietmDatas","customPicture");
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return;
        }
    }
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String path1 = mediaStorageDir.getPath();
    String path2 = path1+"/"+timeStamp+".png";
    sdcardTempFile = new File(path2);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    Uri u = Uri.fromFile(sdcardTempFile);
    intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, xiangji);
}

   @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            System.out.println("requestCode" + requestCode);
            switch (requestCode) {
                case 3:
                    try {
                        Uri xiangji_uri = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(activity.getContentResolver(), sdcardTempFile.getAbsolutePath(), null, null));
                        String path = xiangji_uri.getPath();
                        FileInputStream inputStream = new FileInputStream(path);
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        options.inTempStorage = new byte[100 * 1024];
                        options.inPreferredConfig = Bitmap.Config.RGB_565;
                        options.inPurgeable = true;
                        options.inSampleSize = 4;
                        options.inInputShareable = true;
                        Bitmap bmp = BitmapFactory.decodeStream(inputStream,null,options);
//                        Bitmap bmp = BitmapFactory.decodeStream(xiangji_cr.openInputStream(xiangji_uri));
                        mlist.add(bmp);
                        if (null != mlist && mlist.size()>0){
                            //继续拍照的功能
                            intoPhotos();
                        }
                    } catch (FileNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    break;
            }
        }

首先是调用系统的相机功能,其中因为系统自带相机拍出来的照片的比较高帧,所以内存消耗比较大,我们需要在拍照的时候,对图片进行压缩处理即可避免,详细代码至上,如有bu ming bai

你可能感兴趣的:(知识总结)