android-BitmapFactory.decodeResource使用inJustDecodeBounds = true为outHeight和outWidth返回0
作者:互联网
我正在关注有关有效显示位图的android开发人员教程,并且尝试读取位图的尺寸和类型.
这是我阅读位图的代码:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
image = BitmapFactory.decodeResource(context.getResources(), R.id.myimage, options);
imageHeight = options.outHeight;
imageWidth = options.outWidth;
imageType = options.outMimeType;
我的imageHeight,imageWidth结果似乎都为0,而imageType为null.
该图像是位图格式.
我的onCreate方法是
ImageView imgView = (ImageView) findViewById(R.id.myimage);
Drawable draw = getResources().getDrawable(R.drawable.bmp_login_screen);
imgView.setImageDrawable(draw);
TextView textView = (TextView) findViewById(R.id.text_view);
ReadBitmapDimen dimensions = new ReadBitmapDimen(getApplicationContext());
textView.setText(" Dimensions for userlogin image: outHeight = " + String.valueOf(dimensions.imageHeight));
谢谢!
解决方法:
更改此行-image = BitmapFactory.decodeResource(context.getResources(),R.id.myimage,options);
至
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.bmp_login_screen, options);
标签:bitmapfactory,android 来源: https://codeday.me/bug/20191122/2062496.html