0
버튼 클릭시 내 sd 카드에 이미지를 저장했습니다. 다른 그림을 저장하면 응용 프로그램이 손상되었습니다. 이미지 이름을 동일하게 유지하려면 이전 이미지를 덮어 쓰지 마십시오. 내가 어떻게 이럴 수 있지.sd 카드에 이미지 덮어 쓰기 android
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] image=stream.toByteArray();
System.out.println("byte array:"+image);
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "myfile");
imagesFolder.mkdirs();
String fileName = "myfile.jpg";
File output = new File(imagesFolder, fileName);
while (output.exists()){
fileName = "myfile.jpg";
output = new File(imagesFolder, fileName);
}
while (output.exists()){
fileName = "myfile.jpg";
output = new File(imagesFolder, fileName);
}
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
//bitmap image here
imageFileOS.write(image);
imageFileOS.flush();
imageFileOS.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
아무것도. 모든 이미지에 대해 같은 이름을 설정하십시오. – Riser