I know this question may seem repetitive as compared to a few other questions on here How to save image captured with camera in specific folder[like this] but I am still having trouble. What I'm trying to do is make an app that after you take a picture with the camera, the image will be saved into a new folder (titled after the app name). I am seeing that the folder was created, but the images don't seem to be inserting into them. The following is some of my code where I believe I'm screwing up. Any help out there would be a big help. Thank you!
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();
}
}
Try using this
File file = new File(Environment
.getExternalStorageDirectory()
+ File.separator
+ "/your_folder_name/" + ".png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
if (fos != null) {
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
}
}
Don't forget to add permission to your mainfest file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Try putting this before calling the Camera intent
Uri uriSavedImage=Uri.fromFile(new File("/sdcard/flashCropped.png"));
camera.putExtra("output", uriSavedImage);
startActivityForResult(camera, 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With