费尽周折终于把这块代码凑齐了,以后可以直接用了,需要的小盆友可以参考一下。
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();
}
}
});
}