private Bitmap getBitmap() {
NinePatchDrawable ninePatchDrawable = (NinePatchDrawable) getResources().getDrawable(R.mipmap.bubble1,null);
float ratio = ninePatchDrawable.getIntrinsicWidth() * 1.0f/ ninePatchDrawable.getIntrinsicHeight();
int desiredWidth = 300; // 替换为您希望的宽度
int desiredHeight = 100; // 替换为您希望的高度
Bitmap bitmap = Bitmap.createBitmap(desiredWidth, desiredHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
ninePatchDrawable.setBounds(0, 0, desiredWidth, desiredHeight);
ninePatchDrawable.draw(canvas);
return bitmap;
}
Android 加载.9 png NinePatch 图片为 bitmap
最新推荐文章于 2024-04-15 11:19:48 发布
该代码片段展示了如何从资源中获取一个NinePatchDrawable,调整其大小(保持宽高比),然后创建一个新的Bitmap并用Drawable在Canvas上绘制,以便适应特定的宽度和高度需求。
1832

被折叠的 条评论
为什么被折叠?



