当前位置:网站首页>Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}

Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}

2022-06-30 00:03:00 Dev sunny day

Recently, I wrote a demo Use Glide When loading a picture, you suddenly find that the picture is not loaded , Major errors :

GlideException: Failed DecodePath{
    DirectByteBuffer->GifDrawable->Drawable}

It's strange to check your code , Found the picture url There is a problem ,,,,,

        Glide
        .with(this)
        .load("https://github.com/sunnnydaydev/DataBingding/blob/main/photo/glide_test.png")
        .into(binding.img)

This picture is about yourself github A picture on the project , It may be due to Github#ReadMe Influence , I usually Github#ReadMe When you insert a picture in, you can directly insert the picture link in the project in rich text syntax to display the picture . Therefore use Glide I used this link directly when loading this image .

I've been talking for a long time about why I made a mistake In fact, pictures url There is a problem , This url It represents a page resource on the server , Not a specific picture resource .

Copy the above link to the browser and open it. You will find that the page is like this :

 Insert picture description here
therefore Glide Get this url http After the request, you get the entire web page data . In order to load the picture correctly , Directly specify the correct picture path .

Then there is a problem , since Github#ReadMe The above... Is specified in url, Why can he load this picture correctly ???

I think the website is parsing ReadMe Rich text files are parsed to this url It will automatically go to the real server address of the picture . HMM, the process behind it should be like this .

Now I have another idea , Since the picture has a real server address , Can I find out ? In this way, I may be able to build a github Project placement picture , Then when the client needs to request online pictures, I can directly simulate here

It was found in the following way ,,,,Github#ReadMe page :
 Insert picture description here

 Insert picture description here
Found duplicate pictures url A query parameter is added after pasting it into the browser ?raw = true, then enter Then the magic appeared

 Insert picture description here
The browser automatically goes to the server where the picture is located url, This url Regular :

https://raw.githubusercontent.com/ Yours Github user name /Github Picture in your project

After some exploration, I have gained a lot , However, there are still some things to pay attention to :

  • github In the domestic instability, the opening timeout always occurs
  • raw.githubusercontent.com The resources under this domain name seem to be inaccessible in China , Keep asking for rejection .

The above can be easily solved , Programmers? Just get a ladder

The end Exploration completed , yo-yo ,,,,

原网站

版权声明
本文为[Dev sunny day]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/180/202206292350060194.html