2012-04-02 119 views
1

我正在開發一個Android應用程序,該應用程序從一個Web服務獲取基於64編碼的圖像,並將其顯示在ImageView中。在模擬器上顯示但在Android平板電腦上顯示的圖像

我的問題是圖像在模擬器上正確顯示,但是在平板電腦(帶有Android 4的平板電腦ASUS Transformer)上運行時,ImageView在加載圖像時似乎消失。

這是我使用加載的ImageView代碼:

ImageView imageView = (ImageView) this.findViewById(R.id.floor_map_view); 
Bitmap image = BitmapFactory.decodeByteArray(result, 0, result.length); 
imageView.setImageBitmap(image); 

的圖像從Web服務獲得正確的,正如我所說的是正確加載在模擬器和加上我比較收到的基礎64字符串與我的Web服務發送的字符串匹配。

這是我的活動佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#ffffff"> 


      <ImageView 
       android:contentDescription="floorMapView" 
       android:id="@+id/floor_map_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:src="#222222" 
       /> 



</LinearLayout> 

任何想法可能會發生什麼?

謝謝。

編輯:在BitmapFactory.Options對象中使用inSampleSize,並在decodeByteArray調用中使用inSampleSize使圖像顯示,但如預期的那樣,它應該比它小。

+0

是字符串或ByteArray – 2012-04-02 17:14:21

+0

的byte [],否則便無法正常編譯decodeByteArray需要,顧名思義,一個字節數組作爲參數。 – 2012-04-02 17:16:04

回答

0

我要做的第一件事就是使用調試器檢查調試器和仿真器中的imageViewimage的運行時間值,看看它們是否有所不同。如果他們這樣做,可以更深入地瞭解調用堆棧,以瞭解爲什麼不這樣做,這可能是因爲資源在一個環境中不在同一個地方,或者存在多種原因。

如果事實證明圖像正在加載到活動中,請使用HierarchyViewer檢查活動的佈局元素,然後查看發生的情況(如果它甚至完全丟失)。

+0

運行時沒有明顯差異。 HierarchyViewer似乎只能在仿真器上運行,而不能在實際的設備上運行。 – 2012-04-02 19:59:10

0

增加您的AndroidManifest.xml文件此行

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
在你的代碼的結果
相關問題