mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 12:38:27 +00:00
parent
eedbc667c6
commit
6ae38d0718
@ -16,6 +16,11 @@ import android.util.Pair;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.Priority;
|
import com.bumptech.glide.Priority;
|
||||||
|
import com.bumptech.glide.load.DecodeFormat;
|
||||||
|
import com.bumptech.glide.load.engine.Resource;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.Downsampler;
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.FitCenter;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
import org.thoughtcrime.securesms.mms.MediaConstraints;
|
||||||
|
|
||||||
@ -69,8 +74,8 @@ public class BitmapUtil {
|
|||||||
throws ExecutionException
|
throws ExecutionException
|
||||||
{
|
{
|
||||||
final Pair<Integer, Integer> dimensions = getDimensions(getInputStreamForModel(context, model));
|
final Pair<Integer, Integer> dimensions = getDimensions(getInputStreamForModel(context, model));
|
||||||
final Pair<Integer, Integer> clamped = clampDimensions(dimensions.first, dimensions.second,
|
final Pair<Integer, Integer> clamped = clampDimensions(dimensions.first, dimensions.second,
|
||||||
maxWidth, maxHeight);
|
maxWidth, maxHeight);
|
||||||
return createScaledBitmapInto(context, model, clamped.first, clamped.second);
|
return createScaledBitmapInto(context, model, clamped.first, clamped.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,17 +94,18 @@ public class BitmapUtil {
|
|||||||
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
|
private static <T> Bitmap createScaledBitmapInto(Context context, T model, int width, int height)
|
||||||
throws ExecutionException
|
throws ExecutionException
|
||||||
{
|
{
|
||||||
try {
|
final Bitmap rough = Downsampler.AT_LEAST.decode(getInputStreamForModel(context, model),
|
||||||
return Glide.with(context)
|
Glide.get(context).getBitmapPool(),
|
||||||
.load(model)
|
width, height,
|
||||||
.asBitmap()
|
DecodeFormat.PREFER_RGB_565);
|
||||||
.fitCenter()
|
|
||||||
.skipMemoryCache(true)
|
final Resource<Bitmap> resource = BitmapResource.obtain(rough, Glide.get(context).getBitmapPool());
|
||||||
.into(width, height)
|
final Resource<Bitmap> result = new FitCenter(context).transform(resource, width, height);
|
||||||
.get();
|
|
||||||
} catch (InterruptedException ie) {
|
if (result == null) {
|
||||||
throw new AssertionError(ie);
|
throw new ExecutionException(new BitmapDecodingException("unable to transform Bitmap"));
|
||||||
}
|
}
|
||||||
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> Bitmap createScaledBitmap(Context context, T model, float scale)
|
public static <T> Bitmap createScaledBitmap(Context context, T model, float scale)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user