开发者

android app load and resize images

I need load image from assets开发者_如何学运维 I can read text file

but i can not read images and get to BitmapFactory my simple code

BitmapFactory.decodeFile(resources.getAssets().open("Untitled-1.jpg"));


Images should be placed in the /res/drawable-XXX-folders (see this table).

If you put them in the /res/drawable-XX-folder, you can load them (with Java) using something like this to show it in a ImageView:

ImageView view = (ImageView) this.findViewById(R.id.drawme);
view.setImageResource(R.drawable.android);

If you need it as a Bitmap-Object, you can use the decodeResource()-method BitmapFactory-class:

ImageView image = (ImageView) findViewById(R.id.test_image);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
image.setImageBitmap(bitmap);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜