2

I am able to keep the images of different resolutions inside drawable-hdpi,drawable-mdpi,drawable-ldpi of res folder but do not know how to access the images from assets/www folder . Kindly help.

san
  • 33
  • 1
  • 8

4 Answers4

1

you need to do any thing more to handle multi-resolution.just get the image by id and system will pic automatically as per current resolution.

http://developer.android.com/guide/practices/screens_support.html#range

Dheeresh Singh
  • 15,643
  • 3
  • 38
  • 36
0

You can get an image id by (no matter of dpi):

R.drawable.your_image

So, with id you can do everything that you need (use search).

Dmitry Zaytsev
  • 23,650
  • 14
  • 92
  • 146
0

If you want to use the path try the following :

private void showImage() {
    String uri = "drawable/icon";

    // int imageResource = R.drawable.icon;
    int imageResource = getResources().getIdentifier(uri, null, getPackageName());

    ImageView imageView = (ImageView) findViewById(R.id.myImageView);
    Drawable image = getResources().getDrawable(imageResource);
    imageView.setImageDrawable(image);
}

But it's recommended to use the R references :

int imageResource = R.drawable.icon; 

Drawable image = getResources().getDrawable(imageResource);

Source

drawable-hdpi drawable-mdpi,drawable-ldpi are just different folders to make difference between images quality depending on the screen resolution. The idea is to put the same images in different folder with different resolutions ...

Community
  • 1
  • 1
Mehdi
  • 1,494
  • 5
  • 33
  • 53
0

You don't need the AssetManager. You can do

BitmapFactory.decodeFile("file:///android_asset/www/bullet.jpg")

Though storing Images in the Assets is not the best way to go. You will not be able to take advantage of the Android resource management system. So unless you have a compelling reason to do this, I'd suggest that you take a look at using the res folder and the resources system.

Update: Explanation The BitmapFactory has a method to decode a file via the decodeFile method. That's point one. Android lets you access a file in the assets folder via the file:///android_asset/{path} path. In your case, the Image at /image/Malay/bullet.jpg is the assets folder can be accessed via the the file:///android_asset/www/bullet.jpg

Kavis
  • 98
  • 4