Skip to content

Instantly share code, notes, and snippets.

@babedev
babedev / android-rotate-bitmap.kt
Created February 14, 2018 02:14
Rotate bitmap on Android
fun rotateBitmap(bitmap: Bitmap, orientation: Int): Bitmap? {
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> matrix.setScale(-1F, 1F)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.setRotate(180F)
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
matrix.setRotate(180F)
matrix.postScale(-1F, 1F)
}
@babedev
babedev / ViewExt.kt
Last active February 16, 2018 12:15
Show image with Glide and start intent with Anko
fun ImageView.show(imageUrl: String = "") {
if (imageUrl.isBlank()) return
if (context == null) return
if (context is Activity && ((context as Activity).isFinishing || (context as Activity).isDestroyed)) return
Glide.with(context)
.load(imageUrl)
.crossFade()