androidbitmappicassopixel-density

How can I set the density of images loaded with Picasso?


The images I load with Picasso seem to use a density value of DENSITY_NONE. What do I have to change to make Picasso call .setDensity(160) on the loaded images before they are displayed?


Solution

  • Basing myself on another Picasso solution to resize images I implemented a custom transformation object which sets the density of images to a constant of my own:

    Transformation changeDensity = new Transformation()
    {
        @Override public Bitmap transform(Bitmap source)
        {
            source.setDensity(160);
            return source;
        }
    
        @Override public String key()
        {
            return "density";
        }
    };
    
    // …later…
    
    Picasso
        .with(context)
        .load(imageUri)
        .transform(changeDensity)
        .into(imageView);