美文网首页
Android 9Patch点9图转位图Bitmap的方法

Android 9Patch点9图转位图Bitmap的方法

作者: kongzue | 来源:发表于2019-07-23 12:57 被阅读0次

点9图默认是没有大小尺寸的,需要先指定尺寸后才能获得具体图像,根据资源文件获取位图的方法如下:

参数说明:
context:上下文索引
resId:点9图的资源Id,例如R.drawable.button
width:指定宽度(像素)
height:指定高度(像素)

public Bitmap NinePatch2Bitmap(Context context, int resId, int width, int height) {
    Drawable drawable = context.getResources().getDrawable(resId);
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

相关文章

网友评论

      本文标题:Android 9Patch点9图转位图Bitmap的方法

      本文链接:https://www.haomeiwen.com/subject/jeyolctx.html