Skip to content

Commit

Permalink
Fix resizing an image causes jagged lines on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh1d0w committed Apr 11, 2020
1 parent 14a789c commit 82c0608
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

### Change (v4.6.5)

## 2020-04-11

- Fix resizing an image causes jagged lines on Android

### Change (v4.6.5+rc.1)

## 2020-03-27
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.vitanov.multiimagepicker'
version '4.6.4'
version '4.6.5'

buildscript {
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected ByteBuffer doInBackground(String... strings) {
Activity activity = activityReference.get();
if (activity == null || activity.isFinishing()) return null;

Bitmap sourceBitmap = getCorrectlyOrientedImage(activity, uri);
Bitmap sourceBitmap = getCorrectlyOrientedImage(activity, uri, this.width, this.height);
Bitmap bitmap = ThumbnailUtils.extractThumbnail(sourceBitmap, this.width, this.height, OPTIONS_RECYCLE_INPUT);

if (bitmap == null) return null;
Expand Down Expand Up @@ -746,6 +746,56 @@ private static Bitmap getCorrectlyOrientedImage(Context context, Uri photoUri) t
return srcBitmap;
}

private static Bitmap getCorrectlyOrientedImage(Context context, Uri photoUri, int width, int height) throws IOException {
int orientation = getOrientation(context, photoUri);

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

InputStream is = context.getContentResolver().openInputStream(photoUri);
BitmapFactory.decodeStream(is, null, options);
if (is != null) {
is.close();
}

options.inJustDecodeBounds = false;
options.inDither = false;
options.inSampleSize = calculateInSampleSize(options, width,height);
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;

InputStream is2 = context.getContentResolver().openInputStream(photoUri);
Bitmap srcBitmap = BitmapFactory.decodeStream(is2, null, options);
if (is2 != null) {
is2.close();
}

if (orientation > 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);

srcBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(),
srcBitmap.getHeight(), matrix, true);
}

return srcBitmap;
}

private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int width = options.outWidth;
final int height = options.outHeight;
int inSampleSize = 1;

if (width > reqWidth || height > reqHeight) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}

private void finishWithSuccess(List imagePathList) {
if (pendingResult != null)
pendingResult.success(imagePathList);
Expand Down
2 changes: 1 addition & 1 deletion docs/gettingstarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The first thing we need to do is add the multi_image_picker package to our `pubs

```yaml
dependencies:
multi_image_picker: ^4.6.4
multi_image_picker: ^4.6.5
```
Next we need to install the plugin.
Expand Down
3 changes: 1 addition & 2 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/radoslav/Projects/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/radoslav/Projects/multi_image_picker/example"
export "FLUTTER_TARGET=/Users/radoslav/Projects/multi_image_picker/example/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/radoslav/Projects/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
2 changes: 1 addition & 1 deletion ios/multi_image_picker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'multi_image_picker'
s.version = '4.6.4'
s.version = '4.6.5'
s.summary = 'Multi image picker'
s.description = <<-DESC
A new flutter plugin project.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: multi_image_picker
description: Flutter plugin that allows you to display multi image picker on iOS and Android.
version: 4.6.5+rc.1
version: 4.6.5
homepage: https://github.com/Sh1d0w/multi_image_picker

dependencies:
Expand Down

0 comments on commit 82c0608

Please sign in to comment.