Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

android - Glide load local image by Uri.

I'm trying to use Glide to load an image from local storage with no success.

Glide.with(mContext)
    .load(pictureUri) // Uri of the picture
    .transform(new CircleTransform(..))
    .into(profileAvatar);

This is the error I get:

java.lang.Exception: Failed to load model: '/storage/emulated/0/DCIM/Camera/IMG_20150831_180900.jpg'
at com.bumptech.glide.request.GenericRequest.onSizeReady(GenericRequest.java:441)
at com.bumptech.glide.request.target.ViewTarget$SizeDeterminer.getSize(ViewTarget.java:211)
at com.bumptech.glide.request.target.ViewTarget.getSize(ViewTarget.java:100)
at com.bumptech.glide.request.GenericRequest.begin(GenericRequest.java:272)
at com.bumptech.glide.manager.RequestTracker.resumeRequests(RequestTracker.java:83)
at com.bumptech.glide.RequestManager.resumeRequests(RequestManager.java:180)
at com.bumptech.glide.RequestManager.onStart(RequestManager.java:203)
at com.bumptech.glide.manager.ActivityFragmentLifecycle.onStart(ActivityFragmentLifecycle.java:50)
at com.bumptech.glide.manager.SupportRequestManagerFragment.onStart(SupportRequestManagerFragment.java:135)
at android.support.v4.app.Fragment.performStart(Fragment.java:1986)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1051)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1197)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1179)
at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1996)
at android.support.v4.app.FragmentController.dispatchStart(FragmentController.java:176)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:517)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.Activity.performRestart(Activity.java:6063)
at android.app.Activity.performResume(Activity.java:6068)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2975)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

While waiting for someone to respond, I tried to make a File instance from the Uri and load that. It works! Weird!

Glide.with(mContext)
    .load(new File(pictureUri.getPath())) // Uri of the picture
    .transform(new CircleTransform(..))
    .into(profileAvatar);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...