调用相机拍照,处理图片旋转,保存图片

费尽周折终于把这块代码凑齐了,以后可以直接用了,需要的小盆友可以参考一下。

private void takePic() {
    camera.takePicture(null, null, new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) {

            Bitmap bmptemp=bmptemp= BitmapFactory.decodeByteArray(data,0,data.length);
            //对图片进行旋转处理
            Matrix matrix = new Matrix();
            matrix.reset();
            matrix.postRotate(90);
            Bitmap bMapRotate = Bitmap.createBitmap(bmptemp, 0, 0,bmptemp.getWidth(), bmptemp.getHeight(), matrix, true);

            File filePath = new File(Environment.getExternalStorageDirectory(), "myCamera");
            if(!filePath.exists()) {
                filePath.mkdirs();
            }
            File fileName = new File(filePath, System.currentTimeMillis() + ".jpg");
            try {
                fileName.createNewFile();
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fileName));
                bMapRotate.compress(Bitmap.CompressFormat.JPEG, 100, bos);//将图片压缩到流中
                bos.flush();//输出
                bos.close();//关闭
                Intent intent=new Intent();
                intent.putExtra("filepath",fileName.toString());
                setResult(0,intent);
                finish();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值