GitNex/app/src/main/java/org/mian/gitnex/helpers/Images.java
opyale d8a14105c9 Fixing and improving scaling of images, improving performance by doing work that has to be done once only once and using different terminology. (#831)
remove unknown case for editing

Improve var names and code formatting

Minor improvements.

Restoring ACRA functionality.

Fixing and improving scaling of images, improving performance by doing work that has to be done once only once and using different terminology.

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/831
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-Authored-By: opyale <opyale@noreply.codeberg.org>
Co-Committed-By: opyale <opyale@noreply.codeberg.org>
2021-02-13 20:31:38 +01:00

43 lines
1 KiB
Java

package org.mian.gitnex.helpers;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
/**
* Author M M Arif
*/
public class Images {
public static Bitmap scaleImage(byte[] imageData, int sizeLimit) {
Bitmap original = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
if(original.getHeight() > sizeLimit && original.getWidth() <= original.getHeight()) {
double reductionPercentage = (double) sizeLimit / original.getHeight();
Bitmap scaled = Bitmap.createScaledBitmap(original, (int) (reductionPercentage * original.getWidth()), sizeLimit, false);
original.recycle();
return scaled;
}
else if(original.getWidth() > sizeLimit && original.getHeight() < original.getWidth()) {
double reductionPercentage = (double) sizeLimit / original.getWidth();
Bitmap scaled = Bitmap.createScaledBitmap(original, sizeLimit, (int) (reductionPercentage * original.getHeight()), false);
original.recycle();
return scaled;
}
// Image size does not exceed bounds.
return original;
}
}