将图像显示为字节数组:不起作用

时间:2013-10-17 21:33:21

标签: android byte

我的问题是:我有一个必须用ImageView显示的字节数组。这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   ImageView imageView = (ImageView)findViewById(R.id.show_image);
   byte[] arrayBytes = ...; // It's initialized

   BitmapFactory.Options options = new BitmapFactory.Options();
   options.inSample = 4;
   imageView.setImageBitmap(BitmapFactory.decodeByteArray(arrayBytes, 0, arrayBytes.length,     options));
}

activity_main.xml的代码是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView 
        android:id="@+id/show_image"
        android:contentDescription="@string/Imagen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

但它不起作用:没有显示图像!我做错了什么?

要获取字节数组[],我从文件中读取double [] []数组2D。为我使用的矩阵的每个元素获取字节值:

byte[] byteArray = new byte[SIZE];
int k = 0;

for(...i) {
    for(...j) {
        byteArray[k] = Double.valueOf(matrix[i][j]).byteValue();
        k++;
  }
}

提前致谢

0 个答案:

没有答案
相关问题