display image from byteArray

前端 未结 2 974
野趣味
野趣味 2020-12-14 08:26

I have a Main class with has onCreate() method. in that method i have made the MapFile class\' object.and called its readFile() and

相关标签:
2条回答
  • 2020-12-14 08:45

    adding a byte array to an 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);
    
    0 讨论(0)
  • 2020-12-14 08:48

    I think your issue is not the byteArray but the findViewById. As you say that the NPE is on the first line. There are rules around this method you have two options to call it :

    Either you use it to query a View you already have in the layout you called in setContentView
    Or you use it on a View contained in a layout you inflated manually with a layout inflater

    If you try to use it in your activity to call a View from any other layout than the one in setContentView that you have not inflated yourself, it will return null.

    0 讨论(0)
提交回复
热议问题