aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-06-30 12:01:43 +0200
committeriNPUTmice <daniel@gultsch.de>2014-06-30 12:01:43 +0200
commit121fb58d5e6892c4fd62ac8da90ba45b28e1aafc (patch)
tree3475ff12f4df7424bd032a58dd1d031c2ea010fd /src
parentdcb21cb9e672c08f8731978be5079e1f23130b64 (diff)
possible fix for #232
Diffstat (limited to 'src')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index ca6360b94..1ee68a276 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -11,6 +11,8 @@ import java.io.OutputStream;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Matrix;
+import android.media.ExifInterface;
import android.net.Uri;
import android.util.Log;
import android.util.LruCache;
@@ -85,19 +87,29 @@ public class FileBackend {
return originalBitmap;
}
}
-
- public JingleFile copyImageToPrivateStorage(Message message, Uri image) throws ImageCopyException {
- return this.copyImageToPrivateStorage(message, image,0);
+
+ public Bitmap rotate(Bitmap bitmap, int degree) {
+ int w = bitmap.getWidth();
+ int h = bitmap.getHeight();
+ Matrix mtx = new Matrix();
+ mtx.postRotate(degree);
+ return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
- private JingleFile copyImageToPrivateStorage(Message message, Uri image, int sampleSize)
+ public JingleFile copyImageToPrivateStorage(Message message, Uri image)
throws ImageCopyException {
+ return this.copyImageToPrivateStorage(message, image, 0);
+ }
+
+ private JingleFile copyImageToPrivateStorage(Message message, Uri image,
+ int sampleSize) throws ImageCopyException {
try {
InputStream is;
if (image != null) {
is = context.getContentResolver().openInputStream(image);
} else {
is = new FileInputStream(getIncomingFile());
+ image = getIncomingUri();
}
JingleFile file = getJingleFile(message);
file.getParentFile().mkdirs();
@@ -105,7 +117,8 @@ public class FileBackend {
Bitmap originalBitmap;
BitmapFactory.Options options = new BitmapFactory.Options();
int inSampleSize = (int) Math.pow(2, sampleSize);
- Log.d("xmppService","reading bitmap with sample size "+inSampleSize);
+ Log.d("xmppService", "reading bitmap with sample size "
+ + inSampleSize);
options.inSampleSize = inSampleSize;
originalBitmap = BitmapFactory.decodeStream(is, null, options);
is.close();
@@ -116,6 +129,18 @@ public class FileBackend {
getIncomingFile().delete();
}
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
+ originalBitmap = null;
+ ExifInterface exif = new ExifInterface(image.toString());
+ if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("6")) {
+ scalledBitmap = rotate(scalledBitmap, 90);
+ } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("8")) {
+ scalledBitmap = rotate(scalledBitmap, 270);
+ } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION)
+ .equalsIgnoreCase("3")) {
+ scalledBitmap = rotate(scalledBitmap, 180);
+ }
OutputStream os = new FileOutputStream(file);
boolean success = scalledBitmap.compress(
Bitmap.CompressFormat.WEBP, 75, os);
@@ -138,7 +163,7 @@ public class FileBackend {
R.string.error_security_exception_during_image_copy);
} catch (OutOfMemoryError e) {
++sampleSize;
- if (sampleSize<=3) {
+ if (sampleSize <= 3) {
return copyImageToPrivateStorage(message, image, sampleSize);
} else {
throw new ImageCopyException(R.string.error_out_of_memory);
@@ -190,6 +215,10 @@ public class FileBackend {
public File getIncomingFile() {
return new File(context.getFilesDir().getAbsolutePath() + "/incoming");
}
+
+ public Uri getIncomingUri() {
+ return Uri.parse(context.getFilesDir().getAbsolutePath() + "/incoming");
+ }
public class ImageCopyException extends Exception {
private static final long serialVersionUID = -1010013599132881427L;