Android 调用系统的API拍照,在图片库中显示

//     给定一个Bitmap,进行保存
    public void saveJpeg(Bitmap bm) {
        String savePath = null;
        if (intcount <= 1500) {
            savePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "DCIM/Camera";
            Log.e(TAG, "save bitmap的存储路径是 :" + savePath + "," + "incount的值是:" + intcount);
            File folder = new File(savePath);
            if (!folder.exists()) // 如果文件夹不存在则创建
            {
                folder.mkdir();
            }
        } else if (intcount >= 1501) {
            savePath = Environment.getExternalStorageDirectory().getPath() + File.separator + "DCIM/Camera"
                    + String.valueOf(1000);
            Log.e(TAG, "save bitmap的存储路径是 :" + savePath + "," + "incount的值是:" + intcount);
            File folder2 = new File(savePath);
            if (!folder2.exists()) // 如果文件夹不存在则创建
            {
                folder2.mkdir();
            }


        }
        long dataTake = System.currentTimeMillis();
        String jpegName = savePath + File.separator +"IMG_"+ dataTake +"_"+intcount+"_"+ ".jpg";
        Log.e(TAG, "saveJpeg:jpegName--" + jpegName);
        File jpegFile = new File(jpegName);
        try {
            FileOutputStream fout = new FileOutputStream(jpegName);
            BufferedOutputStream bos = new BufferedOutputStream(fout);
            // TODO: 2018/8/8  100就表示 不压缩 
            bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);

            // TODO: 2018/8/9 保存到图片库 ,可以看到
            MediaStore.Images.Media.insertImage(CameraAct.this.getContentResolver(),
                    jpegFile.getAbsolutePath(), jpegName, null);
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri uri = Uri.fromFile(new File(jpegName));
            System.out.println(jpegName+"uriuri:::"+uri);
            intent.setData(uri);
            sendBroadcast(intent);

            bos.flush();
            bos.close();
            mCamera.stopPreview();
            mCamera.startPreview();
            bm.recycle();


            // succCount = succCount + 1;
            Log.e(TAG, "saveJpeg:存储完毕!-->" + succCount);
        } catch (IOException e) {


            Log.e(TAG, "saveJpeg:存储失败!-->" + failCount);
            e.printStackTrace();
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值