mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-22 06:01:12 +00:00
Resize content images
This commit is contained in:
parent
1dce96a460
commit
c8e830aff2
1 changed files with 31 additions and 5 deletions
|
@ -317,11 +317,37 @@ class ImageHelper {
|
||||||
try {
|
try {
|
||||||
Uri uri = Uri.parse(a.source);
|
Uri uri = Uri.parse(a.source);
|
||||||
Log.i("Loading image source=" + uri);
|
Log.i("Loading image source=" + uri);
|
||||||
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
|
||||||
Drawable d = Drawable.createFromStream(inputStream, uri.toString());
|
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||||
if (d == null)
|
|
||||||
|
BitmapFactory.Options options;
|
||||||
|
try (InputStream is = context.getContentResolver().openInputStream(uri)) {
|
||||||
|
options = new BitmapFactory.Options();
|
||||||
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeStream(is, null, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
int scaleToPixels = dm.widthPixels;
|
||||||
|
int factor = 1;
|
||||||
|
while (options.outWidth / factor > scaleToPixels)
|
||||||
|
factor *= 2;
|
||||||
|
|
||||||
|
Bitmap bm;
|
||||||
|
try (InputStream is = context.getContentResolver().openInputStream(uri)) {
|
||||||
|
if (factor > 1) {
|
||||||
|
options.inJustDecodeBounds = false;
|
||||||
|
options.inSampleSize = factor;
|
||||||
|
bm = BitmapFactory.decodeStream(is, null, options);
|
||||||
|
} else
|
||||||
|
bm = BitmapFactory.decodeStream(is);
|
||||||
|
|
||||||
|
if (bm == null)
|
||||||
throw new FileNotFoundException(a.source);
|
throw new FileNotFoundException(a.source);
|
||||||
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
}
|
||||||
|
|
||||||
|
Drawable d = new BitmapDrawable(res, bm);
|
||||||
|
d.setBounds(0, 0, Math.round(bm.getWidth() * dm.density), Math.round(bm.getHeight() * dm.density));
|
||||||
|
|
||||||
if (view != null)
|
if (view != null)
|
||||||
fitDrawable(d, a, view);
|
fitDrawable(d, a, view);
|
||||||
return d;
|
return d;
|
||||||
|
|
Loading…
Reference in a new issue