Fix issue #521 - Automatically compress images if needed for avoiding to draw too large bitmap.
This commit is contained in:
parent
4aee720095
commit
a1b5d4f50d
|
@ -373,7 +373,8 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
new SimpleTarget<Bitmap>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
imageView.setImageBitmap(resource);
|
||||
Bitmap imageCompressed = Helper.compressImageIfNeeded(MediaActivity.this, resource);
|
||||
imageView.setImageBitmap(imageCompressed);
|
||||
Glide.with(getApplicationContext())
|
||||
.asBitmap()
|
||||
.load(finalUrl).into(
|
||||
|
@ -381,9 +382,10 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
@Override
|
||||
public void onResourceReady(@NonNull final Bitmap resource, Transition<? super Bitmap> transition) {
|
||||
loader.setVisibility(View.GONE);
|
||||
Bitmap imageCompressed = Helper.compressImageIfNeeded(MediaActivity.this, resource);
|
||||
if( imageView.getScale() < 1.1) {
|
||||
downloadedImage = resource;
|
||||
imageView.setImageBitmap(resource);
|
||||
imageView.setImageBitmap(imageCompressed);
|
||||
}else{
|
||||
message_ready.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -391,7 +393,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
downloadedImage = resource;
|
||||
imageView.setImageBitmap(resource);
|
||||
imageView.setImageBitmap(imageCompressed);
|
||||
message_ready.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2277,6 +2277,22 @@ public class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
public static Bitmap compressImageIfNeeded(Context context, Bitmap bmToCompress){
|
||||
|
||||
int size = bmToCompress.getByteCount();
|
||||
double resizeby = 33554432; //4Mo
|
||||
double resize = ((double)size)/resizeby;
|
||||
if( resize > 1 ) {
|
||||
Bitmap newBitmap = Bitmap.createScaledBitmap(bmToCompress, (int) (bmToCompress.getWidth() / resize),
|
||||
(int) (bmToCompress.getHeight() / resize), true);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
newBitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
|
||||
return newBitmap;
|
||||
}
|
||||
return bmToCompress;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||
public static void largeLog(String content) {
|
||||
if (content.length() > 4000) {
|
||||
|
|
Loading…
Reference in New Issue