title: Download image from URL and draw it on canvas - Android
body: <p>I am trying to download an image from server using Retrofit library. The server returns a byte array of the image, which is then converted to Bitmap using <code>BitmapFactory.decodeByteArray(..)</code>. But when I call <code>canvas.drawBitmap(..)</code>, my applications crashes and following message is displayed in LogCat </p>
  
  <p><code>Fatal signal 11 (SIGSEGV), code 1, fault addr 0x188 android</code></p>
  
  <p>After searching on stackoverflow, I came across an answer that said set <code>android:hardwareAccelerated</code> to <code>false</code>. I did and not only my app got laggy and slow, the image was still not drawn on canvas. I know that the <code>left</code> and <code>top</code> coordinates passed in <code>canvas.drawBitmap(....)</code> are correct as I can display an image that is loaded from mipmap. </p>
  
  <p>Any help on this would be appreciated as I am stuck on this issue for some time now and can't find a suitable solution  to this. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>LogCat at the time of crash</p>
  
  <pre><code>                         ----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
  </code></pre>
  
  <p><strong>Method called for fetching and drawing Image</strong></p>
  
  <p>I am calling this method in <code>onDraw()</code> after calculating left and top which are correct like I said above. </p>
  
  <pre><code>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&lt;ServerResponse&lt;FetchProfileImageResponse&gt;&gt; call = profileServiceRetrieveImage.fetchProfileImage("retrieveImage.action", "", imageID);
          call.enqueue(new RetrofitCallback&lt;ServerResponse&lt;FetchProfileImageResponse&gt;&gt;() {
              @Override
              protected void onSuccess(ServerResponse&lt;FetchProfileImageResponse&gt; objectServerResponse) {
                  FetchProfileImageResponse dao = objectServerResponse.getResponsePayload();
                  Bitmap bmp = BitmapFactory.decodeByteArray(dao.getBinaryData(), 0, dao.getBinaryData().length);
                  canvas.drawBitmap(bmp, left, top, paint);
              }
          });
      }
  </code></pre>