开发者

android app load and resize images

开发者 https://www.devze.com 2023-03-10 12:03 出处:网络
I need load image from assets开发者_如何学运维 I can read text file but i can not read images and get to BitmapFactory

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

精彩评论

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

关注公众号