【发布时间】:2012-12-07 10:15:10
【问题描述】:
与How to save image captured with camera in specific folder[like this] 上的其他一些问题相比,我知道这个问题似乎是重复的,但我仍然遇到问题。我想做的是制作一个应用程序,在你用相机拍照后,图像将保存到一个新文件夹中(以应用程序名称命名)。我看到该文件夹已创建,但图像似乎没有插入其中。以下是我认为我搞砸的一些代码。任何帮助都会有很大的帮助。谢谢!
camera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
}
});
}
private void saveToFile(String message) throws Exception {
String filePath = getFilesDir()+"";
File file = new File(filePath + "/sdcard/DCIM/100MEDIA/Wardobe");
FileOutputStream out = new FileOutputStream(file, true);
out.write(message.getBytes());
out.close();
saveImage(filePath, "/sdcard/DCIM/100MEDIA/Wardobe/image.jpg", bmp);
if(battleborn != null) {
saveImage(filePath, "sdcard/DCIM/100MEDIA/Wardrobe/image.jpg", bmp);
}
}
public void saveImage(String path, String dir, Bitmap image) {
try{
FileOutputStream fos = new FileOutputStream(path + dir);
BufferedOutputStream stream = new BufferedOutputStream(fos);
bmp.compress(CompressFormat.JPEG, 50, stream);
stream.flush();
stream.close();
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
Intent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage) ?
-
不要硬编码 sdcard 路径。使用环境 .getExternalStorageDirectory()
标签: android camera save directory image