对于代码加载图片,作为背景时候,有时候我们需要加载 点9图,所以需要先判断一下,避免当初普通图片应用
ImageView im_0 = (ImageView) findViewById(R.id.im_0);
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.help_my_item);
final byte[] chunk = bitmap.getNinePatchChunk();
if (!NinePatch.isNinePatchChunk(chunk)) {
Log.i("TAG", "不是 .9.png");
im_0.setBackgroundDrawable(new BitmapDrawable(bitmap));
} else {
NinePatchDrawable d = new NinePatchDrawable(getResources(), bitmap, chunk, new Rect(), null);
im_0.setBackgroundDrawable(d);
}
本文介绍了一种方法来判断加载的图片是否为.9图,并根据判断结果正确设置图片为背景。通过示例代码展示了如何使用BitmapFactory、NinePatch等API实现这一功能。
4381

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



