saj*_*joo 22 arrays android image
我有一个Main有onCreate()方法的课.在那个方法中,我已经使MapFile类'对象.readFile()并调用它和readIndex()方法.在readIndex()方法中我调用另一个名为MapTilewhere的类,我从二进制文件中读取图像切片,然后我必须显示我的图像.
问题是,如何在不将我的代码放入onCreate(Bundle savedInstanceStare)方法的情况下显示图像?我正在尝试这种方式,但在第一线它给了我NullPointerException.
ImageView image = (ImageView) findViewById(android.R.id.icon);
Bitmap bMap = BitmapFactory.decodeByteArray(imageTile, 0, imageTile.length);
image.setImageBitmap(bMap);
Run Code Online (Sandbox Code Playgroud)
bsa*_*ner 34
将一个字节数组添加到android imageview:
//byte[] chartData
ImageView imgViewer = (ImageView) findViewById(R.id.chart_image);
Bitmap bm = BitmapFactory.decodeByteArray(chartData, 0, chartData.length);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
imgViewer.setMinimumHeight(dm.heightPixels);
imgViewer.setMinimumWidth(dm.widthPixels);
imgViewer.setImageBitmap(bm);
Run Code Online (Sandbox Code Playgroud)
我认为你的问题不是byteArray而是findViewById.正如你所说,NPE在第一线.有这个方法的规则你有两个选项来调用它:
要么使用它来查询您在调用的布局中已有的视图,setContentView
要么在包含在使用布局inflater手动充气的布局中的视图上使用它
如果您尝试在活动中使用它来从任何其他布局调用视图而不是setContentView您自己没有膨胀的布局,它将返回null.
| 归档时间: |
|
| 查看次数: |
32079 次 |
| 最近记录: |