아래와 같은 코드로 변환된 이미지를 버튼을 누르면 저장하는 것으로 하고 있는데요,
이게 이상하게 즉각적으로 이미지가 생성되지 않고, 한참 후에야 어느순간에 갤러리를 들어갔을때
이미지가 생성되있고 그러더라고요. 무엇을 고쳐야될까요, 쓰레드문제 그런걸까요.. ㅠㅠ
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveBitmaptoJpeg(afterInvert, "ColorIt", fileName );
Log.d("save", fileName + "저장 하였음");
Toast.makeText(getApplicationContext(), "저장이 완료되었습니다.", Toast.LENGTH_SHORT).show();
}
});
}
// 변환 이미지 저장을 위한 코드
public static void saveBitmaptoJpeg(Bitmap bitmap,String folder, String name){
String ex_storage = Environment.getExternalStorageDirectory().getAbsolutePath();
// Get Absolute Path in External Sdcard
String folder_name = "/"+folder+"/";
String file_name = name+".jpg";
String string_path = ex_storage+folder_name;
File file_path;
file_path = new File(string_path);
if(file_path.exists() == false){
file_path.mkdirs();
Log.d("save", "새 디렉토리 생성");
}
try{
FileOutputStream out = new FileOutputStream(string_path+file_name);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.close();
Log.d("save", "코드상 비트맵 저장을 완수하였음.");
}catch(FileNotFoundException exception){
Log.d("FileNotFoundException", "파일 없음");
}catch(IOException exception){
Log.d("IOException", "예외 발생");
}
}