Last active
          October 7, 2023 05:10 
        
      - 
      
- 
        Save miao1007/3f7e9b5f011fc188eba6 to your computer and use it in GitHub Desktop. 
    Gradient Transformation For Picasso
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /** | |
| * Created by Miao1007 on 2/2/15. | |
| * | |
| * Original Code: https://gist.github.com/miao1007/3f7e9b5f011fc188eba6 | |
| */ | |
| public class GradientTransformation implements Transformation { | |
| int startColor = Color.argb(240,0,0,0); | |
| int endColor = Color.TRANSPARENT; | |
| @Override public Bitmap transform(Bitmap source) { | |
| int x = source.getWidth(); | |
| int y = source.getHeight(); | |
| Bitmap grandientBitmap = source.copy(source.getConfig(), true); | |
| Canvas canvas = new Canvas(grandientBitmap); | |
| //left-top == (0,0) , right-bottom(x,y); | |
| LinearGradient grad = | |
| new LinearGradient(x/2, y, x/2, y/2, startColor, endColor, Shader.TileMode.CLAMP); | |
| Paint p = new Paint(Paint.DITHER_FLAG); | |
| p.setShader(null); | |
| p.setDither(true); | |
| p.setFilterBitmap(true); | |
| p.setShader(grad); | |
| canvas.drawPaint(p); | |
| source.recycle(); | |
| return grandientBitmap; | |
| } | |
| @Override public String key() { | |
| return "Gradient"; | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Picasso.with(context) | |
| .load(url) | |
| .transform(new GradientTransformation()) | |
| .into(imageview); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This gradient color is not smooth