4

I'm currently following a tutorial for an Uber clone and at this part

 carMarker = mMap.addMarker(new MarkerOptions()
                     .position(currentPosition)
                     .flat(true)
                     .icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));

where we add the marker of the car into the current position for moving it from point to point, the app crashes and the debbuger says "Failed to decode image. The provided image must be a Bitmap".
The 'car' image is a png file inside the drawable folder, I've tryied some solutions as Custom marker in google maps in android with vector asset icon and others, but none actually solved.

Can anyone help here? For me it looks like it's all fine: the image is a png file, it's on the drawable folder, why is it not considering as a bitmap?

E.Akio
  • 2,249
  • 3
  • 14
  • 27
  • 1
    would the line `bmp = BitmapFactory.decodeResource(getResources(), R.drawable.car);` from [this answer](https://stackoverflow.com/questions/49665965/app-crashes-on-converting-a-bitmap-of-png-image) work? Either way, I want to commend you for that question - I assumed it would be easy to find an exact duplicate, but no. Well done :) – lucidbrot Oct 14 '18 at 18:55
  • 1
    [this Answer](https://stackoverflow.com/a/33766508/2550406) suggests that android cannot load a PNG in that way. I would be surprised by that, but do other image types work? How about other images of the same type `.png`? – lucidbrot Oct 14 '18 at 19:02
  • @lucidbrot switching "BitmapDescriptorFactory..." to your bmp gives an error of "Cannot be applied". And thank for the commendation, there is no easy duplicate because the answer is more a lack of attention hehe – E.Akio Oct 14 '18 at 19:49
  • @lucidbrot jpg files worked ok here, but since they are jpg, they were with their borders (which isnt so good visually) – E.Akio Oct 14 '18 at 19:51

2 Answers2

3

I found the answer. When pasting the car file inside the drawable folder, Android Studio gives options of drawable source folders to save it, the default option is the "drawable-v24" folder aaand the R.drawable takes the image inside the "drawable" folder. So it needs to change from "drawable-v24" to "drawable" when pasting the image and that will work.

E.Akio
  • 2,249
  • 3
  • 14
  • 27
  • @IzzyStannett what is happening to your program? – E.Akio Jan 30 '20 at 13:20
  • 1
    I had the same error message, "Failed to decode image. The provided image must be a Bitmap". I realised my problem was due to the fact the bitmaps hadn't been properly formed yet, and were therefore still null (legacy codebase!). I solved it by re-ordering the call of events. – Izzy Stannett Feb 03 '20 at 16:43
1

Try This. Convert PNG images into jpg format and make sure the resolution of the image is not too high. I had the same experience and then I used jpg with low-resolution images.