Skip to content

Instantly share code, notes, and snippets.

@vashisthg
Created October 20, 2017 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vashisthg/3760502fc911db876546b894c265eac0 to your computer and use it in GitHub Desktop.
Save vashisthg/3760502fc911db876546b894c265eac0 to your computer and use it in GitHub Desktop.
import android.graphics.Bitmap
import timber.log.Timber
/**
* Picasso transformation to Crop an image from top.
* Created by Gaurav Vashisth on 20/10/17.
*/
class CropFromTopTransformation constructor(private val cropDistance: Int): com.squareup.picasso.Transformation {
override fun transform(source: Bitmap): Bitmap {
val width = source.width
val height = source.height
val clipImage = Bitmap.createBitmap(source, 0, cropDistance, width, height - cropDistance);
if (source != clipImage) {
source.recycle()
}
return clipImage
}
override fun key(): String {
return "CropFromTopTransformation" + cropDistance
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment