显示来自 byteArray 的图像 [英] display image from byteArray

查看:27
本文介绍了显示来自 byteArray 的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 onCreate() 方法的 Main 类.在该方法中,我创建了 MapFile 类的对象.并调用了它的 readFile()readIndex() 方法.在 readIndex() 方法中,我调用另一个名为 MapTile 的类,在那里我从我的二进制文件中读取图像图块,然后我必须显示我的图像.

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.

问题是,如何在不将代码放入 onCreate(Bundle savedInstanceStare) 方法的情况下显示图像?我正在尝试这种方式,但在第一行它给了我 NullPointerException.

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

推荐答案

我认为您的问题不是 byteArray,而是 findViewById.正如您所说,NPE 在第一行.围绕此方法有一些规则,您有两种选择可以调用它:

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 :

要么使用它来查询在 setContentView
中调用的布局中已有的视图或者你在你使用布局充气器手动充气的布局中包含的视图上使用它

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

如果您尝试在您的 Activity 中使用它从任何其他布局调用视图,而不是您自己没有膨胀的 setContentView 中的布局,它将返回 null.

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.

这篇关于显示来自 byteArray 的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆