square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.72k stars 3.97k forks source link

Transformation not applied to drawables which are referenced by ID. #262

Closed PepijnK closed 11 years ago

PepijnK commented 11 years ago

Hi,

I'm using Picasso 2.0.2. When I do the following call:

Picasso.with(getContext()) .load(R.drawable.empty_profile_image) .fit() .transform(new MakeRoundTransformation()) .into(imageView);

I'm not getting the applied transformation image in the imageview. However when I do the call on a web resource, I do see the transformation.

dnkoutso commented 11 years ago

Interesting...I'll try to reproduce.

dnkoutso commented 11 years ago

Sorry for being a bit late on this. Will try to tackle it over weekend.

dnkoutso commented 11 years ago

I could not reproduce. I managed to apply a transformation to the placeholder drawable. See screenshot.

Picasso.with(this).load(R.drawable.placeholder).transform(new MakeRoundTransformation()).into(imageView);

device-2013-09-29-085337

PepijnK commented 11 years ago

Ok, let me try again tomorrow and make a screenshot/elaborate when I see it happen. Op 29 sep. 2013 17:54 schreef "Dimitris" notifications@github.com het volgende:

I could not reproduce. I managed to apply a transformation to the placeholder drawable. See screenshot.

[image: device-2013-09-29-085337]https://f.cloud.github.com/assets/310370/1233336/605974ea-291f-11e3-9b69-7ede89e61b83.png

— Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/262#issuecomment-25322671 .

PepijnK commented 11 years ago

Inside a custom view which gets re-used by an adapter:

...

mAuthorThumbIV.setVisibility(View.VISIBLE);
Picasso.with(getContext())
                    .load(R.drawable.empty_profile_image)
                    .fit()
                    .transform(new MakeRoundTransformation())
                    .into(mAuthorThumbIV);

And here is the result:

screenshot_2013-10-01-13-33-13

JakeWharton commented 11 years ago

Please don't use the API for that. Pre-round the drawable or use an ImageView subclass which clamps the canvas with a shader (like this).

PepijnK commented 11 years ago

Yeah, but then the image will look different as the circle I draw around the drawable will be scaled. I prefer to have the same look then to optimise for a corner case. Why couldn't I use Picasso for this? Op 1 okt. 2013 17:36 schreef "Jake Wharton" notifications@github.com het volgende:

Please don't use the API for that. Pre-round the drawable or use an ImageView subclass which clamps the canvas with a shader (like thishttp://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ ).

— Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/262#issuecomment-25459988 .

PepijnK commented 11 years ago

BTW, The transformation is also not applied to the drawable in the placeholder() call.

JakeWharton commented 11 years ago

It's not supposed to be. The placeholder is used while the download and transformation of the real image is occurring. On Oct 2, 2013 5:13 AM, "PepijnK" notifications@github.com wrote:

BTW, The transformation is also not applied to the drawable in the placeholder() call.

— Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/262#issuecomment-25533527 .

PepijnK commented 11 years ago

OK, that might be silly from me... Although I would like to use Picasso for all my image transformations, including the current loading one and error image (when the targeted could not be loaded) as my MakeRoundTransformation also includes drawing a white line around the images. Using any pre-rounded image will result in inconsistency regarding the white surrounding line as they should appear in different sizes.

Could I use Picasso for this?

On Wed, Oct 2, 2013 at 4:31 PM, Jake Wharton notifications@github.comwrote:

It's not supposed to be. The placeholder is used while the download and transformation of the real image is occurring. On Oct 2, 2013 5:13 AM, "PepijnK" notifications@github.com wrote:

BTW, The transformation is also not applied to the drawable in the placeholder() call.

— Reply to this email directly or view it on GitHub< https://github.com/square/picasso/issues/262#issuecomment-25533527> .

— Reply to this email directly or view it on GitHubhttps://github.com/square/picasso/issues/262#issuecomment-25543154 .

JakeWharton commented 11 years ago

No. No transformations will be applied to placeholder or error drawables. Subclass image view and use a shader which clamps the bitmap round and draws the white border (as linked above) if you want this behavior.

JakeWharton commented 11 years ago

I, like @dnkoutso, was unable to repro the failure. Transformations were applied to the drawable correctly inside of a custom view used in an adapter. Please link to a zip of a working project that demonstrates this issue for us to re-open.

mbarrben commented 10 years ago

Hi,

I've run into a similar issue. I managed to create a simple project with one activity and a silly transformation, and the ImageView just remains empty.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView imageView = (ImageView) findViewById(R.id.image_view);

        Picasso.with(this)
            .load(android.R.drawable.ic_menu_save)
            .transform(new SillyTransformation(this))
            .into(imageView);
    }

    private static class SillyTransformation implements Transformation {

        private Context context;

        public SillyTransformation(Context context) {
            this.context = context;
        }

        @Override
        public String key() {
            return "SillyTransformation";
        }

        @Override
        public Bitmap transform(Bitmap source) {
            return BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_delete);
        }

    }
}

Hope it helps.

dnkoutso commented 10 years ago

I believe this is an issue with picasso. Did you try source.recycle() in your transform() method? I think it crashes silently.

Also use an error(R.drawable.error) to check something went wrong.

mbarrben commented 10 years ago

If I use an error(R.drawable.error), the result is the same: empty ImageView.

However, recycling the source Bitmap in transform method makes it work. I think it might be what you say: Picasso is silently crashing.

dnkoutso commented 10 years ago

There is an issue for that already tagged and will be fixed on next version. I am keeping this thread closed.

Next version should come end of November.