|
32 | 32 | import android.support.annotation.DrawableRes;
|
33 | 33 | import android.support.annotation.FloatRange;
|
34 | 34 | import android.support.annotation.IntRange;
|
| 35 | +import android.support.annotation.NonNull; |
35 | 36 | import android.support.v4.content.ContextCompat;
|
36 | 37 | import android.view.View;
|
37 | 38 |
|
@@ -358,6 +359,35 @@ public static Bitmap getBitmap(final FileDescriptor fd,
|
358 | 359 | return BitmapFactory.decodeFileDescriptor(fd, null, options);
|
359 | 360 | }
|
360 | 361 |
|
| 362 | + /** |
| 363 | + * Return the bitmap with the specified color. |
| 364 | + * |
| 365 | + * @param src The source of bitmap. |
| 366 | + * @param color The color. |
| 367 | + * @return the bitmap with the specified color |
| 368 | + */ |
| 369 | + public static Bitmap drawColor(@NonNull final Bitmap src, @ColorInt final int color) { |
| 370 | + return drawColor(src, color, false); |
| 371 | + } |
| 372 | + |
| 373 | + /** |
| 374 | + * Return the bitmap with the specified color. |
| 375 | + * |
| 376 | + * @param src The source of bitmap. |
| 377 | + * @param color The color. |
| 378 | + * @param recycle True to recycle the source of bitmap, false otherwise. |
| 379 | + * @return the bitmap with the specified color |
| 380 | + */ |
| 381 | + public static Bitmap drawColor(@NonNull final Bitmap src, |
| 382 | + @ColorInt final int color, |
| 383 | + final boolean recycle) { |
| 384 | + if (isEmptyBitmap(src)) return null; |
| 385 | + Bitmap ret = recycle ? src : src.copy(src.getConfig(), true); |
| 386 | + Canvas canvas = new Canvas(ret); |
| 387 | + canvas.drawColor(color, PorterDuff.Mode.DARKEN); |
| 388 | + return ret; |
| 389 | + } |
| 390 | + |
361 | 391 | /**
|
362 | 392 | * Return the scaled bitmap.
|
363 | 393 | *
|
|
0 commit comments