Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem save image to disk #1688

Closed
ghost opened this issue Oct 22, 2017 · 2 comments
Closed

problem save image to disk #1688

ghost opened this issue Oct 22, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 22, 2017

i use this class


public class PhotoLoader implements Target {
    private final String name;
    private ImageView imageView;
    public PhotoLoader(String name, ImageView imageView) {
        this.name = name;
        this.imageView = imageView;
    }
    public PhotoLoader(String name) {
        this.name = name;
        this.imageView = null;
    }
    @Override
    public void onPrepareLoad(Drawable arg0) {
    }
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom arg1) {
        File file = new File(App.getDirctory() + "/" + name);
        try {
            file.createNewFile();
            FileOutputStream ostream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 75, ostream);
            ostream.close();
            if(imageView != null)
            imageView.setImageBitmap(bitmap);
        } catch (Exception e) {
            log.d(App.TAG_TEST,"Error :"+e.toString());
        }
    }
    @Override
    public void onBitmapFailed(Drawable arg0) {
    }
}

and calling

File folderProfile = new File(getDirctory(), "profile");
        if (!folderProfile.exists()) {
            folderProfile.mkdirs();
        }

        Log.d(TAG_TEST,"getImageAvatar : "+Compte.getImageAvatar());
        if(Compte.getImageAvatar() != null && !Compte.getImageAvatar().isEmpty()) {
            Picasso.with(App.getContext()).load(Compte.getImageAvatar()).priority(Picasso.Priority.HIGH).memoryPolicy(MemoryPolicy.NO_CACHE).into(new PhotoLoader(getAbsPathAvatar()));
        }

        Log.d(TAG_TEST,"getImageCover : "+Compte.getImageCover());
        if(Compte.getImageCover() != null && !Compte.getImageCover().isEmpty()) {
            Picasso.with(App.getContext()).load(Compte.getImageCover()).priority(Picasso.Priority.HIGH).memoryPolicy(MemoryPolicy.NO_CACHE).into(new PhotoLoader(getAbsPathCover()));
        }

is save once not save all image ,same time save first one and same time second , i dont understand this this problem , and i see #506 but in dont understand how use?

Picasso.with(App.getContext()).load("http://......")..into("target class").save(file);

but function save not showing me in editor ?

PS: sorry my english is very bad .

@NightlyNexus
Copy link
Contributor

You need to hold a reference to the Target elsewhere. Picasso only stores a weak reference to the passed-in Target.

@JakeWharton
Copy link
Collaborator

There's also an issue for explicit file save already. On mobile so can't grab it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants