/**
* Converts a {@link Drawable} into a {@link Bitmap}. Includes an optimization in case the {@link Drawable} in question is already a
* {@link BitmapDrawable}.
*
* @param drawable A Drawable instance to convert
* @param width The width of the new Bitmap
* @param height The height of the new Bitmap
* @return A new {@link Bitmap} instance constraint to width and height dimensions supplied, never {@code null}
*/
@NonNull
@SuppressWarnings("unused")
public static Bitmap drawableToBitmap(@NonNull final Drawable drawable, @Px final int width, @Px final int height) {
final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(result);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return result;
}
SillyAndroid.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:silly-android
作者:
评论列表
文章目录