Rotate camera image send

This commit is contained in:
Margaux Clerc 2015-05-12 17:33:59 +02:00
parent 3bf5905bc0
commit 7702f7567a

View file

@ -22,9 +22,8 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.security.Timestamp;
import android.graphics.Matrix;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
@ -43,6 +42,8 @@ import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.mediastream.Log;
import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.BubbleChat;
import android.media.ExifInterface;
import android.support.v4.content.CursorLoader;
import android.annotation.SuppressLint;
@ -558,6 +559,26 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
bm = Bitmap.createScaledBitmap(bm, (SIZE_MAX * bm.getWidth()) / bm.getHeight(), SIZE_MAX, false);
}
// Rotate the bitmap if possible/needed, using EXIF data
Log.w(path);
try {
if (path != null) {
ExifInterface exif = new ExifInterface(path);
int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
Matrix matrix = new Matrix();
if (pictureOrientation == 6) {
matrix.postRotate(90);
} else if (pictureOrientation == 3) {
matrix.postRotate(180);
} else if (pictureOrientation == 8) {
matrix.postRotate(270);
}
bm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
}
} catch (Exception e) {
e.printStackTrace();
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();