이미지 편집기 앱을 개발 중이므로 사용자가 이미지를 저장할 때마다 그렇게합니다. 그래서 우선은이미지가 동일한 이름으로 덮어 쓰지 않습니다
String savedImageURL = MediaStore.Images.Media.insertImage(
getContentResolver(),
bitmap,
"Bird",
"Image of bird"
);
이 코드를 삽입하지만, 새로운 파일을 생성하는 대신 덮어 쓰기.
그래서 내가 다른 방법
public String saveImage(String folderName, String imageName) {
String selectedOutputPath = "";
if (isSDCARDMounted()) {
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), folderName);
// Create a storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d("PhotoEditorSDK", "Failed to create directory");
}
}
// Create a media file name
selectedOutputPath = mediaStorageDir.getPath() + File.separator + imageName;
Log.d("PhotoEditorSDK", "selected camera path " + selectedOutputPath);
File file = new File(selectedOutputPath);
try {
FileOutputStream out = new FileOutputStream(file,true);
if (parentView != null) {
parentView.setDrawingCacheEnabled(true);
parentView.getDrawingCache().compress(Bitmap.CompressFormat.JPEG, 80, out);
}
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return selectedOutputPath;
}
를 사용하지만, 그것은 또한 작동하지 않았다.
누구나 같은 이름으로 비트 맵을 덮어 쓴다는 것을 알고 있습니까? 둘째 인수로 거짓
예외가 발생합니까 아니면 새 파일입니까? –
어떤 오류가 발생합니까? –
나는 모든 오류가 발생하지 않았다. 모든 것이 잘 작동하지만 이미지는 같은 이름이나 파일로 덮어 쓰지 않는다. 첫 번째 저장된 섹션 만 파일에 덮어 쓰지 않는 두 번째 섹션을 삽입합니다. – Dithesh