앱에서 사진 촬영을 한후 이미지뷰에서 촬영한 사진을 출력할려고하니
URL NULL 포인트가 발생합니다.
갤러리에서 가져와서는 출력이 되는데....
수정방안 알려주세요.
public void select_picture(String rec_string){
switch (rec_string){
case "0":
Intent takeapicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takeapicture, CAMERA_CODE);
break;
case "1":
Intent take_picture = new Intent(Intent.ACTION_PICK);
take_picture.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
take_picture.setType("image/*");
startActivityForResult(Intent.createChooser(take_picture, "Select Picture"), GALLERY_CODE);
break;
case "2":
image.setVisibility(View.VISIBLE);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.mipmap.noimage);
image.setImageBitmap(bm);//이미지 뷰에 비트맵 넣기
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case GALLERY_CODE:
SendPicture(data); //갤러리에서 가져오기
break;
case CAMERA_CODE:
SendPicture(data); //카메라에서 가져오기
break;
default:
break;
}
}
}
private void SendPicture(Intent data) {
Uri imgUri = data.getData();
String imagePath = getRealPathFromURI(imgUri); // path 경로
ExifInterface exif = null;
try {
exif = new ExifInterface(imagePath);
} catch (IOException e) {
e.printStackTrace();
}
int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
int exifDegree = exifOrientationToDegrees(exifOrientation);
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);//경로를 통해 비트맵으로 전환
image.setVisibility(View.VISIBLE);
image.setImageBitmap(rotate(bitmap, exifDegree));//이미지 뷰에 비트맵 넣기
}
public int exifOrientationToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}
public Bitmap rotate(Bitmap src, float degree) {
// Matrix 객체 생성
Matrix matrix = new Matrix();
// 회전 각도 셋팅
matrix.postRotate(degree);
// 이미지와 Matrix 를 셋팅해서 Bitmap 객체 생성
return Bitmap.createBitmap(src, 0, 0, src.getWidth(),
src.getHeight(), matrix, true);
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}