you*_*san 1 java android bitmap nine-patch
我有一个9补丁drawable作为XML.当我尝试使用它BitmapFactory.decode
来获取位图时,它会返回null
.无论如何从这个资源获取位图?
nine_patch.xml:
<?xml version="1.0" encoding="utf-8"?>
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/empty_icon_video" >
</nine-patch>
Run Code Online (Sandbox Code Playgroud)
而代码是:
BitmapFactory.decodeResource(mResources, resId);
Run Code Online (Sandbox Code Playgroud)
Bitmap bmp = Bitmap.createBitmap(yourWidth, yourHeight, Bitmap.Config.ARGB_8888);
Drawable drawable = getResources().getDrawable(R.drawable.resId);
Canvas canvas = new Canvas(bmp);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
Run Code Online (Sandbox Code Playgroud)
试试这个.现在,位图将在其上绘制九个补丁.您可以提供不同的宽度和高度.
归档时间: |
|
查看次数: |
2772 次 |
最近记录: |