[英]how to use images present in drawable-hdpi,drawable-mdpi,drawable-ldpi of res folder?
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 . 我能够将res文件夹的drawable-hdpi,drawable-mdpi,drawable-ldpi保留在不同分辨率的图像中,但不知道如何从assets / www文件夹访问图像。 Kindly help. 请帮助。
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. 您需要做更多的事情来处理多分辨率。只需按id获取图像,系统就会根据当前分辨率自动拍照。
http://developer.android.com/guide/practices/screens_support.html#range http://developer.android.com/guide/practices/screens_support.html#range
You can get an image id by (no matter of dpi): 您可以通过以下方式获得图像ID :(与dpi无关):
R.drawable.your_image
So, with id you can do everything that you need (use search). 因此,使用id,您可以做您需要的所有事情(使用搜索)。
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 : 但是建议使用R
引用:
int imageResource = R.drawable.icon;
Drawable image = getResources().getDrawable(imageResource);
drawable-hdpi drawable-mdpi,drawable-ldpi
are just different folders to make difference between images quality depending on the screen resolution. drawable-hdpi drawable-mdpi,drawable-ldpi
是不同的文件夹,根据屏幕分辨率,图像质量之间会有所不同。 The idea is to put the same images in different folder with different resolutions ... 想法是将相同的图像以不同的分辨率放在不同的文件夹中...
You don't need the AssetManager. 您不需要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. 您将无法利用Android资源管理系统。 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. 因此,除非您有充分的理由这样做,否则建议您看看使用res文件夹和资源系统。
Update: Explanation The BitmapFactory has a method to decode a file via the decodeFile method. 更新:解释BitmapFactory有一个方法可以通过encodeFile方法解码文件。 That's point one. 这是第一点。 Android lets you access a file in the assets folder via the file:///android_asset/{path} path. Android允许您通过file:/// android_asset / {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
在您的情况下,可以通过file:///android_asset/www/bullet.jpg
来访问/image/Malay/bullet.jpg处的图片是资产文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.