1.Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
if (resultCode == Activity.RESULT_OK) {
Bundle bundle = data.getExtras();
Bitmap bitmap = (Bitmap) bundle.get("data");
file = Util.getDate2() + ".jpg";
path = Room.getSDRootString() + file;
FileOutputStream b = null;
File f = new File(path);
try {
b = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
b.flush();
b.close();
} catch (IOException e) {
e.printStackTrace();
} }
}
}
}
——————————这么写的话,我的照片被压缩到20K左右了。但是我想得到原图。
2.file = Util.getDate() + ".jpg";
picpathsave = Room.getFileRoot() + file;
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

try {
uri = Uri.fromFile(new File(picpathsave));
} catch (Exception e) {
e.printStackTrace();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, TAKE_PICTURE);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
if (resultCode == Activity.RESULT_OK) {
editorPhoto.putString(file, file);
                                          ......——————————————————这样写的话,原图是有了,但是Intent data是null,我就无法通过Intent获取之前的数据,而且存在一个兼容性bug,就是在相机拍照保存之后,理应结束相机回到系统,可是部分机型和rom有一定的几率会重新打开相机(这样又生成了一个照片名字,原来那个照片的名字就被覆盖了),而我方法2中的照片名字是全局变量。真心求教。找了很多资料,自己也写了几种不同的方法都有问题,以上两种问题还算最小的了!

解决方案 »

  1.   

    我觉得吧。。最恶心的地方在于,第二个方法的问题。我下午使用调用媒体库的方法去获取照片。
    可是1、返回intent的null所以没法使用。2、有一台机子不一定概率出现保存照片之后重新进入相机。重点是第二个问题,不知道大家有没有遇到过。如果是这样,那么所有网上的,在进入相机时命名的方法基本都无法兼容了。