我一直在使用相机应用程序,它只是将相机拍摄的照片存储在自定义文件夹中。我遇到了一个奇怪的错误,我无法找到重复的问题。虽然我的应用程序采取并将图片保存在文件夹中,但图像不可见。关于这一点的更奇怪的部分是可以查看存储在Camera Shots文件夹(我的手机的默认图片存储点)中的图像副本。我试过用很多不同的方法修改我的代码,但我仍然得到相同的结果。以下是我的代码。任何帮助将不胜感激! 谢谢!
camera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String name = Environment.getExternalStorageDirectory().toString();
File mainFolder = new File(name + "/Filename/");
mainFolder.mkdirs();
Random generator = new Random();
int random = 10000;
random = generator.nextInt(random);
String fileName = "Image-"+ random +".jpg";
File file = new File (mainFolder, fileName);
if (file.exists ()) file.delete ();
try {
FileOutputStream stream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream);
stream.flush();
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
startActivityForResult(i, cameraData);
}
});
答案 0 :(得分:0)
我明白了。我错过了URI。以下是遇到此问题的任何人的更新(和工作)代码:
camera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String name = Environment.getExternalStorageDirectory().toString();
File mainFolder = new File(name + "/Filename/");
mainFolder.mkdirs();
Random generator = new Random();
int random = 10000;
random = generator.nextInt(random);
String fileName = "Image-"+ random +".jpg";
File file = new File (mainFolder, fileName);
Uri uriSavedImage = Uri.fromFile(file);
i.putExtra("output", uriSavedImage);
startActivityForResult(i, cameraData);
}
});