mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-20 13:17:08 +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 {
|
||||
Uri uri = Uri.parse(a.source);
|
||||
Log.i("Loading image source=" + uri);
|
||||
InputStream inputStream = context.getContentResolver().openInputStream(uri);
|
||||
Drawable d = Drawable.createFromStream(inputStream, uri.toString());
|
||||
if (d == null)
|
||||
throw new FileNotFoundException(a.source);
|
||||
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
||||
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
fitDrawable(d, a, view);
|
||||
return d;
|
||||
|
|
Loading…
Reference in a new issue