2016-08-15 91 views
0

我正嘗試從服務器上使用Retrofit庫下載圖像。服務器返回圖像的字節數組,然後使用BitmapFactory.decodeByteArray(..)將其轉換爲位圖。但是,當我打電話canvas.drawBitmap(..),我的應用程序崩潰,並顯示在logcat的從URL下載圖像並在畫布上繪製 - Android

Fatal signal 11 (SIGSEGV), code 1, fault addr 0x188 android

以下消息計算器搜索後,我碰到的是該組android:hardwareAcceleratedfalse答案。我做了,不僅我的應用程序變得遲緩而且緩慢,圖像仍然沒有畫在畫布上。我知道在canvas.drawBitmap(....)中傳遞的lefttop座標是正確的,因爲我可以顯示從mipmap加載的圖像。

對此的任何幫助將不勝感激,因爲我在此問題上停留了一段時間,無法找到合適的解決方案。

編輯

logcat的在呼籲獲取和繪畫圖像

我打電話onDraw()這種方法計算左側和頂部後墜毀

      ----Beginning of crash 
A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x188 in tid 22133 
W/System: ClassLoader referenced unknown path: /data/app/com.i2c.bb4me-2/lib/x86_64 
I/MultiDex: VM with version 2.1.0 has multidex support 
I/MultiDex: install 
I/MultiDex: VM has multidex support, MultiDex support library is disabled. 
I/GMPM: App measurement is starting up, version: 8487 
I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE 
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead. 
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 

方法的時間,這像我上面所說的那樣是正確的。

private void getBitmap(final Canvas canvas, long imageID, final float left, final float top, final Paint paint) { 
     ProfileService profileServiceRetrieveImage = AppManager.getServiceManager().getService(ProfileService.class); 
     Call<ServerResponse<FetchProfileImageResponse>> call = profileServiceRetrieveImage.fetchProfileImage("retrieveImage.action", "", imageID); 
     call.enqueue(new RetrofitCallback<ServerResponse<FetchProfileImageResponse>>() { 
      @Override 
      protected void onSuccess(ServerResponse<FetchProfileImageResponse> objectServerResponse) { 
       FetchProfileImageResponse dao = objectServerResponse.getResponsePayload(); 
       Bitmap bmp = BitmapFactory.decodeByteArray(dao.getBinaryData(), 0, dao.getBinaryData().length); 
       canvas.drawBitmap(bmp, left, top, paint); 
      } 
     }); 
    } 
+1

您是否嘗試過畢加索或Glide?他們是非常好的圖像庫。 –

+0

是的,我知道那些圖書館。但我不能使用它們。在我的工作場所遵循的架構不允許使用它們 –

+0

你是否真的decodeByteArray不返回null?如果您的應用程序崩潰,您將在LogCat中提到錯誤/例外。請張貼他們。一條線然後是一條線。 – greenapps

回答

0

發佈解決方案,以防萬一有人遇到像我這樣的問題。

首先,請不要在onSuccess中撥打canvas.drawBitmap(....)。只需將onSuccess中檢索的位圖保存在一個類中,請致電invalidate()並撥打電話canvas.drawBitmap(...)onDraw()