使用glide顯示gif動圖時, 報錯
http://pic.wenwen.soso.com/pqpic/wenwenpic/0/20171116143737-1895154083_gif_398_305_3740344/0
在瀏覽器能夠打開動圖,? 但是glide加載時只顯示靜態(tài)圖片, 并且log有錯誤:
Glide: Load failed for http://pic.wenwen.soso.com/pqpic/wenwenpic/0/20171116143738-1327109971_gif_405_293_3665345/0 with size [-2147483648x-2147483648]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ContentLengthInputStream->GifDrawable->GifDrawable}, REMOTE
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ContentLengthInputStream->GifDrawable->GifDrawable}
發(fā)現這個問題的原因是因為上面那個gif圖片格式不夠完整, 只有63幀,? 而原始圖有95幀, 原始圖地址:
https://wx2.sinaimg.cn/large/866a67c7gy1fkaw7ewstng20b208hhdx.gif
而在瀏覽器 或者ios系統(tǒng)上都能支持這個圖片的動畫展示.? 說明人家的解碼庫很健壯.
(同事說即刻的gif解碼器是native層的,? 聽起來很高大上啊)
而glide的解碼庫? 其實就是一個java文件了,? 從名字看就好像是說要按照標準的gif格式來.:com.bumptech.glide.gifdecoder.StandardGifDecoder.java
最終解決方案:? 只能比照這個解碼器, 自己修改一下, 讓其兼容格式不完整的gif圖片,? 而怎么把自己定制的而這個解碼器對象, 賦值給glide, 達到替換原始解碼器的效果.? 為了后面這個事情, 折騰了一下午,? 對glide的掌握還是不夠深入啊.
最終搞定了, 已經放到github上, 目前還是純java層的實現, 據說當頁面上gif動圖顯示太多時會有效率問題,后續(xù)考慮在native層重寫一遍
https://github.com/shaopx/InCompleteGifDecoder