这是绘制资源目前正在加载的图像 -
Currently am loading image from drawable resource-
<ImageView
android:id="@+id/stestImg"
android:src="@drawable/testImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
我可以用图像从资产在这里,直接到布局XML?我需要做任何编码的!请帮忙。
can I use image from assets here, directly to the layout XML? Do I need to do any coding for that! Please help.
您可以通过这种方式做到这一点::
ImageView i;
Bitmap bm = getBitmapFromAsset("pic1.png");
i = (ImageView)findViewById(R.id.image);
i.setImageBitmap(bm);
拨打方法::
private Bitmap getBitmapFromAsset(String strName) throws IOException
{
AssetManager assetManager = getAssets();
InputStream istr = assetManager.open(strName);
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}