Fix canvas too large crash (#830)
fix crash by scaling the image resolution Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/830 Reviewed-by: 6543 <6543@noreply.codeberg.org> Co-Authored-By: M M Arif <mmarif@noreply.codeberg.org> Co-Committed-By: M M Arif <mmarif@noreply.codeberg.org>
This commit is contained in:
parent
44b8ad8d1c
commit
711711274e
@ -2,10 +2,7 @@ package org.mian.gitnex.activities;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
@ -38,6 +35,7 @@ import org.mian.gitnex.databinding.ActivityFileViewBinding;
|
|||||||
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
|
||||||
import org.mian.gitnex.helpers.AlertDialogs;
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
import org.mian.gitnex.helpers.AppUtil;
|
import org.mian.gitnex.helpers.AppUtil;
|
||||||
|
import org.mian.gitnex.helpers.Images;
|
||||||
import org.mian.gitnex.helpers.Markdown;
|
import org.mian.gitnex.helpers.Markdown;
|
||||||
import org.mian.gitnex.helpers.Toasty;
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
||||||
@ -182,8 +180,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
|||||||
imageView.setVisibility(View.VISIBLE);
|
imageView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
||||||
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
|
||||||
imageView.setImageDrawable(imageDrawable);
|
imageView.setImageBitmap(Images.scaleImage(imageData, 1920, 1920));
|
||||||
}
|
}
|
||||||
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
||||||
|
|
||||||
|
32
app/src/main/java/org/mian/gitnex/helpers/Images.java
Normal file
32
app/src/main/java/org/mian/gitnex/helpers/Images.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
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 maxSizeWidth, int maxSizeScaledWidth) {
|
||||||
|
|
||||||
|
Bitmap scaledImage;
|
||||||
|
Bitmap image = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
|
||||||
|
int orgWidth = image.getWidth();
|
||||||
|
int orgHeight = image.getHeight();
|
||||||
|
|
||||||
|
if(orgWidth > maxSizeWidth) {
|
||||||
|
|
||||||
|
int aspectRatio = orgWidth / orgHeight;
|
||||||
|
int scaledHeight = maxSizeScaledWidth * aspectRatio;
|
||||||
|
scaledImage = Bitmap.createScaledBitmap(image, maxSizeScaledWidth, scaledHeight, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
scaledImage = Bitmap.createScaledBitmap(image, orgWidth, orgHeight, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return scaledImage;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user