欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > 固定Drawable大小

固定Drawable大小

2024/10/25 9:24:36 来源:https://blog.csdn.net/sonichty/article/details/140011440  浏览:    关键词:固定Drawable大小

获取应用图标直接使用,有些会撑破布局,需要固定大小。

https://blog.51cto.com/u_16213367/8811342

BitmapDrawable 可以强制转换,其他类型Drawable需要重绘。

AdaptiveIconDrawable cannot be cast to BitmapDrawable

https://blog.csdn.net/u011905115/article/details/96434062


NinePatchDrawable cannot be cast to BitmapDrawable

https://blog.csdn.net/Kitty_Landon/article/details/49493717

Drawable icon = packageInfo.applicationInfo.loadIcon(PM);
AppInfo appInfo = new AppInfo();
appInfo.setAppIcon(resizeDrawable(getApplicationContext(), icon, 200, 200));Drawable resizeDrawable(Context context, Drawable drawable, int newWidth, int newHeight) {// 将Drawable转换为Bitmap    Bitmap bitmap;if (drawable instanceof BitmapDrawable) {bitmap = ((BitmapDrawable) drawable).getBitmap();} else {bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());drawable.draw(canvas);}// 缩放BitmapBitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false);// 将Bitmap转换为Drawablereturn new BitmapDrawable(context.getResources(), resizedBitmap);
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com