Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

android - display image from byteArray

I have a Main class with has onCreate() method. in that method i have made the MapFile class' object.and called its readFile() and readIndex() methods. in readIndex() method i call another class named MapTile where i read the images tiles from my binary file and there i have to display my image.

Question is, how can I display an image without putting my code into onCreate(Bundle savedInstanceStare) method? I am trying this way but on first line it gives me NullPointerException.

ImageView image = (ImageView) findViewById(android.R.id.icon);           
Bitmap bMap = BitmapFactory.decodeByteArray(imageTile, 0, imageTile.length);
image.setImageBitmap(bMap);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...