title: Custom marker bitmap error Failed to decode image. The provided image must be a Bitmap
body: <p>I'm using the firebase realtime database to get some users info and show a custom marker for each one.. to set the icon for the marker options I use the method below and it works for most cases.</p>
  
  <p>But more often the app crashes when creating the bitmap of the custom view for the marker..! Is there a way to improve the method and prevent bitmap problems.!</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>  { // other methods.. 
  
      private void showMarker() {
  
      BitmapDescriptor pin = BitmapDescriptorFactory
          .fromBitmap(getMarkerBitmapFromView(data.getUserAvatar()));
          userMarker = googleMap.addMarker(new MarkerOptions()
              .position(latLng)
              .title(data.getName() + "")
              .snippet(data.getSectionName() + "")
              .icon(pin));
        }
  
         // I take pic url from firebase and show it into the marker view
        private Bitmap getMarkerBitmapFromView(String ImgUrl) {
          if (getActivity() != null) {
  
            View customMarkerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.map_marker, null);
            CircleImageView markerImageView = customMarkerView.findViewById(R.id.pic_user);
            FrameLayout pin = customMarkerView.findViewById(R.id.marker);
            pin.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.map_marker_green));
  
             Picasso.with(getActivity())
               .load(ImgUrl)
               .resize(80, 80)
               .error(R.drawable.user_dummy)
               .placeholder(R.drawable.user_dummy)
               .into(markerImageView);
  
            customMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            customMarkerView.layout(0, 0, customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight());
            customMarkerView.buildDrawingCache(true);
  
            Bitmap returnedBitmap = Bitmap.createBitmap(customMarkerView.getMeasuredWidth(), customMarkerView.getMeasuredHeight(), Config.ARGB_8888);
  
            Canvas canvas = new Canvas(returnedBitmap);
            canvas.drawColor(Color.WHITE, Mode.SRC_IN);
            Drawable drawable = customMarkerView.getBackground();
            if (drawable != null) {
              drawable.draw(canvas);
            }
            customMarkerView.draw(canvas);
            return returnedBitmap;
          } else {
           // the crash didn't happen because of this! I've checked using breakpoints, it returns bitmap 99.9% of times.
            return null; 
          }
        }
  
      }
  </code></pre>
  
  <p><strong>The Error</strong> </p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.arapeak.katateeb, PID: 30706
      com.google.maps.api.android.lib6.common.apiexception.b: Failed to decode image. The provided image must be a Bitmap.
      at com.google.maps.api.android.lib6.impl.k.a(:com.google.android.gms.dynamite_dynamitemodulesb@12529020@12.5.29 (040308-192802242):5)
     at com.google.maps.api.android.lib6.impl.o.a(:com.google.android.gms.dynamite_dynamitemodulesb@12529020@12.5.29 (040308-192802242):7)
     at com.google.maps.api.android.lib6.impl.db.&lt;init&gt;(:com.google.android.gms.dynamite_dynamitemodulesb@12529020@12.5.29 (040308-192802242):25)
     at com.google.maps.api.android.lib6.impl.bc.a(:com.google.android.gms.dynamite_dynamitemodulesb@12529020@12.5.29 (040308-192802242):496)
     at com.google.android.gms.maps.internal.l.onTransact(:com.google.android.gms.dynamite_dynamitemodulesb@12529020@12.5.29 (040308-192802242):94)
     at android.os.Binder.transact(Binder.java:387)
     at com.google.android.gms.internal.zzeu.zza(Unknown Source)
     at com.google.android.gms.maps.internal.zzg.addMarker(Unknown Source)
     at com.google.android.gms.maps.GoogleMap.addMarker(Unknown Source)
  </code></pre>