从Android中的drawable/assets文件夹正确加载大图像
我从assets/drawable NoPDI文件夹中获得了一个相当大的图像。 图像大小为1173x1285497KB。 它无法加载 一次创建从Android中的drawable/assets文件夹正确加载大图像,android,bitmap,bitmapfactory,Android,Bitmap,Bitmapfactory,我从assets/drawable NoPDI文件夹中获得了一个相当大的图像。 图像大小为1173x1285497KB。 它无法加载 一次创建 AssetManager assetManager = this.getAssets(); Bitmap bitmap = null; InputStream is = null; try { is = assetManager.open("indoormapimg.png"); bitma
AssetManager assetManager = this.getAssets();
Bitmap bitmap = null;
InputStream is = null;
try {
is = assetManager.open("indoormapimg.png");
bitmap = decodeSampledBitmapFromResource(is, 100, 100); //trying 100x100
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("tag", String.valueOf("Bitmap: " + bitmap));
方法
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth)
if (width > height)
inSampleSize = Math.round((float)height / (float)reqHeight);
else
inSampleSize = Math.round((float)width / (float)reqWidth);
return inSampleSize;
}
及
我也尝试过使用资源。没用。。
我还尝试了BitmapFactory的inJustBounds
true和false。还带有标度内的
我似乎无法加载任何图像,我的日志总是返回null
编辑:
我也在努力
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), ResID);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
opts.inScaled = false;
Bitmap bitmapImage = BitmapFactory.decodeResource(this.getResources(), ResID, opts);
Log.d("tag", String.valueOf("Bitmap: " + bitmap + " BitmapImage: " + bitmapImage));
返回位图:null BitmapImage:null
另外,LogCat显示解码返回false,结果是我解码的文件被破坏了。我不得不更改原始文件。谢谢。您是否从资产中获得了输入信息。
drawable nodpi
文件夹进入res文件夹。但是由于您在assets文件夹中有这个文件,您可以尝试更改assetManager.open(“indoormapimg.png”)toassetManager.open(“drawable nodpi/indoormapimg.png”)
并查看是否有效是的,我知道drawable nodpi
文件夹会进入res文件夹,即使它在那里,BitmapFactory.decodeResource(getResources(),ResID)
返回空值。即使使用inJustBounds
或inScaled
选项。@useletters您的问题有解决方案吗?我的问题还没有解决方案BitmapFactory.decodeResource(getResources(),resd)
始终返回null,即使您可以在res/drawable nodpi/
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), ResID);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
opts.inScaled = false;
Bitmap bitmapImage = BitmapFactory.decodeResource(this.getResources(), ResID, opts);
Log.d("tag", String.valueOf("Bitmap: " + bitmap + " BitmapImage: " + bitmapImage));