Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to avoid using Bitmap.createScaledBitmap as recommended #291

Open
wants to merge 1 commit into
base: feature/non_native
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.media.ExifInterface;
import android.net.Uri;
Expand Down Expand Up @@ -114,9 +117,18 @@ private boolean crop() throws IOException {
float scaleY = mMaxResultImageSizeY / cropHeight;
float resizeScale = Math.min(scaleX, scaleY);

Bitmap resizedBitmap = Bitmap.createScaledBitmap(mViewBitmap,
Math.round(mViewBitmap.getWidth() * resizeScale),
Math.round(mViewBitmap.getHeight() * resizeScale), false);
int srcWidth = mViewBitmap.getWidth();
int srcHeight = mViewBitmap.getHeight();
int dstWidth = Math.round(mViewBitmap.getWidth() * resizeScale);
int dstHeight = Math.round(mViewBitmap.getHeight() * resizeScale);

Rect srcRect = new Rect(0, 0, srcWidth, srcHeight);
Rect dstRect = new Rect(0, 0, dstWidth, dstHeight);

Bitmap resizedBitmap = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(resizedBitmap);
canvas.drawBitmap(mViewBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG));

if (mViewBitmap != resizedBitmap) {
mViewBitmap.recycle();
}
Expand Down