0
갤러리에서 비트 맵을 SD 카드의 경로로 복사하려고합니다.갤러리에서 비트 맵 읽기 및 sd 카드에 쓰기 실패
이 기능은 카메라로 촬영 한 사진 잘 작동 :
public void saveBitmap(Bitmap bitMap, Uri avatarUri) throws Exception{
File file = new File(avatarUri.toString());
// if (file.exists()) file.delete();
try {
OutputStream fOut = new FileOutputStream(file);
if (bitMap.compress(Bitmap.CompressFormat.PNG, 100, fOut)) {
fOut.flush();
fOut.close();
} else {
Log.d("123", "compress file");
}
} catch (Exception e) {
Log.d("123", "File not found file");
}
}
하지만 난 사용하여 갤러리에서 이미지를 선택하면 :
void getImageFromGallery(Intent data) throws FileNotFoundException {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = context.getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
avatarBitmap = bitmap;
}
을 그리고에 saveBitmap()
방법을 사용 이 선택된 이미지를 저장하면 File not found
예외가 발생합니다.
이 메서드는 폴더를 생성하고 saveBitmap()
메서드에 대한 URI를 반환합니다.
public Uri generateAvatarImageUri(String patientName) {
Date date = new Date(0);
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss");
String filename = sdf.format(date) + patientName;
return Uri.fromFile(new File(getExternalStorageDirectory(), avatarFolderPath+filename+".jpg"));
}
}
도움이 필요하십니까?