Android 加载.9 png NinePatch 图片为 bitmap

    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,开发,android)