我是靠谱客的博主 负责月饼,这篇文章主要介绍android上,如何将9png绘制在canvas上,现在分享给大家,希望可以做个参考。

需要使用google特别提供的NinePatchDrawable,使用方法如下:

public Drawable getNinePatchDrawable(int resid,Rect rect){
    InputStream is = getResources().openRawResource(resid);
    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig = Bitmap.Config.RGB_565;
    NinePatchDrawable npd = (NinePatchDrawable) Drawable.createFromResourceStream(getResources(), null, is, null, opt);
    npd.setBounds(rect);
    try{
        is.close();
    }catch(IOException e){
        e.printStackTrace();
    }
    return npd;
}

如果要对这张9png进行大小设置的话,使用它自带的setBounds就好,上述代码已经包含~


最后

以上就是负责月饼最近收集整理的关于android上,如何将9png绘制在canvas上的全部内容,更多相关android上内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部