From 3c8440f70366259ce5232f46b62a3677451d74d7 Mon Sep 17 00:00:00 2001 From: dmcBig Date: Thu, 31 May 2018 10:22:28 +0800 Subject: [PATCH] fix android compress rotat bug --- package.json | 6 ++++-- plugin.xml | 2 +- readme.md | 3 ++- src/android/MediaPicker.java | 12 +++++++++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0cbd644..d5abcaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-mediapicker-dmcbig", - "version": "2.1.5", + "version": "2.1.6", "description": "android ios mediaPicker support selection of multiple image and video", "cordova": { "id": "cordova-plugin-mediapicker-dmcbig", @@ -20,7 +20,9 @@ "cordova-android", "cordova-ios", "mediaPicker", - "videoPicker" + "videoPicker", + "compress", + "fileToBlob" ], "author": "dmcBig", "license": "ISC", diff --git a/plugin.xml b/plugin.xml index 69ee008..9a7b42e 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ - + MediaPicker diff --git a/readme.md b/readme.md index 9a0de1c..64159a7 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ -# MediaPicker v:2.1.1 +# MediaPicker v:2.1.5 android ios mediaPicker support selection of multiple image and video +[GitHub:](https://github.com/dmcBig/cordova-plugin-mediaPicker) https://github.com/dmcBig/cordova-plugin-mediaPicker How do I use? ------------------- diff --git a/src/android/MediaPicker.java b/src/android/MediaPicker.java index 3cd5942..6d78ae9 100644 --- a/src/android/MediaPicker.java +++ b/src/android/MediaPicker.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Matrix; import android.media.ExifInterface; import android.media.ThumbnailUtils; import android.provider.MediaStore; @@ -249,7 +250,7 @@ public class MediaPicker extends CordovaPlugin { ByteArrayOutputStream baos = new ByteArrayOutputStream(); String compFileName="dmcMediaPickerCompress"+System.currentTimeMillis()+".jpg"; File file= new File(cordova.getActivity().getExternalCacheDir(),compFileName); - BitmapFactory.decodeFile(path).compress(Bitmap.CompressFormat.JPEG, quality, baos); + rotatingImage(getBitmapRotate(path),BitmapFactory.decodeFile(path)).compress(Bitmap.CompressFormat.JPEG, quality, baos); try { FileOutputStream fos = new FileOutputStream(file); fos.write(baos.toByteArray()); @@ -284,6 +285,15 @@ public class MediaPicker extends CordovaPlugin { return degree; } + private static Bitmap rotatingImage(int angle, Bitmap bitmap) { + //rotate image + Matrix matrix = new Matrix(); + matrix.postRotate(angle); + + //create a new image + return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, + true); + } public byte[] extractThumbnailByte(String path,int mediaType,int quality) {