카메라에서 이미지를 캡처하고 갤러리에서 이미지를 선택합니다. 삼성 전자 기기에서는 캡쳐 후 이미지가 회전합니다.카메라 또는 갤러리에서 이미지를 회전하는 방법.
회전 한 이미지를 똑바로 회전하고 싶습니다.
나는 그것을하려고했지만 그 효과가 없습니다.
private void onCaptureImageResult(Intent data) {
try {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".png");
FileOutputStream fo;
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
profileImage = destination;
Bitmap rotatedBitmap = modifyOrientation(thumbnail, profileImage.getAbsolutePath());
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream1); //replace 100 with desired quality percentage.
byte[] byteArray1 = stream1.toByteArray();
File tempFile1 = File.createTempFile("temp", null, getCacheDir());
FileOutputStream fos1 = new FileOutputStream(tempFile1);
fos1.write(byteArray1);
if (rotatedBitmap != null) {
profileImageView.setImageBitmap(rotatedBitmap);
profileImage = tempFile1;
} else {
profileImageView.setImageBitmap(thumbnail);
profileImage = destination;
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
Bitmap bm=null;
if (data != null) {
try {
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData());
} catch (IOException e) {
e.printStackTrace();
}
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream); //replace 100 with desired quality percentage.
byte[] byteArray = stream.toByteArray();
try {
File tempFile = File.createTempFile("temp",null, getCacheDir());
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(byteArray);
profileImage = tempFile;
Bitmap rotatedBitmap = modifyOrientation(bm,profileImage.getAbsolutePath());
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream1); //replace 100 with desired quality percentage.
byte[] byteArray1 = stream1.toByteArray();
File tempFile1 = File.createTempFile("temp",null, getCacheDir());
FileOutputStream fos1 = new FileOutputStream(tempFile1);
fos1.write(byteArray1);
if(rotatedBitmap != null) {
profileImageView.setImageBitmap(rotatedBitmap);
profileImage = tempFile1;
}
else {
profileImageView.setImageBitmap(bm);
profileImage = tempFile;
}
}
catch (IOException e)
{
}
}
편집 :
내가 지금 카메라 의도를 사용하고 의도에서 여전히 작동하지 않는 해당 경로를 얻기 위해 노력했다.
private void onCaptureImageResult(Intent data) {
try {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".png");
FileOutputStream fo;
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
Bitmap rotatedBitmap = null;
// profileImage = destination;
Uri tempUri = getImageUri(getApplicationContext(),thumbnail);
// CALL THIS METHOD TO GET THE ACTUAL PATH
File finalFile = new File(getRealPathFromURI(tempUri));
ExifInterface ei = new ExifInterface(finalFile.getAbsolutePath());
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotateImage(thumbnail, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotateImage(thumbnail, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotateImage(thumbnail, 270);
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
break;
}
if (rotatedBitmap != null) {
profileImageView.setImageBitmap(rotatedBitmap);
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
rotatedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream1); //replace 100 with desired quality percentage.
byte[] byteArray1 = stream1.toByteArray();
File tempFile1 = File.createTempFile("temp", null, getCacheDir());
FileOutputStream fos1 = new FileOutputStream(tempFile1);
fos1.write(byteArray1);
profileImage = tempFile1;
} else {
profileImageView.setImageBitmap(thumbnail);
profileImage = destination;
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}
public String getRealPathFromURI(Uri uri) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
return cursor.getString(idx);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_FILE)
onSelectFromGalleryResult(data);
else if (requestCode == REQUEST_CAMERA)
onCaptureImageResult(data);
}
}
지금 뭐야?
아무도 도와 줄 수 있습니까? 무슨 일있어? 감사합니다 ..
가능한 복제를 사용하여 ...
회전 비트 맵 활동 결과 방법이 코드를 넣어 이미지를 회전하는 가치를 인트로가 안드로이드의 일부 장치에서 회전하게 됨] (0120-385-331) – earthw0rmjim
You 나를 포함해야한다. thod'modifyOrientation'이이 질문에서 그 방법이 문제라고 생각하기 때문에 – HendraWD
예. 추가하는 것을 잊어 버렸습니다 .. 편집 된 질문을 확인하십시오 .. @Hendra Wijaya Djiono – Sid