bitmaputil improvement (#2485)
This commit is contained in:
@@ -4,10 +4,8 @@ import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
@@ -15,6 +13,7 @@ import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -180,7 +179,7 @@ public class BitmapUtils {
|
||||
@Nullable
|
||||
public static Drawable getDrawableFromRes(@NonNull Context context, @DrawableRes int drawableRes,
|
||||
@Nullable @ColorInt Integer tintColor) {
|
||||
Drawable drawable = context.getDrawable(drawableRes);
|
||||
Drawable drawable = ContextCompat.getDrawable(context, drawableRes);
|
||||
if (drawable == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -189,11 +188,7 @@ public class BitmapUtils {
|
||||
return drawable;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
drawable.setTint(tintColor);
|
||||
} else {
|
||||
drawable.mutate().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
drawable.setTint(tintColor);
|
||||
return drawable;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user