Android Glide transform旋转rotate圆图CircleCrop,Kotlin
Kotlin
import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.TransformationUtils
class MainActivity : AppCompatActivity() {
private val TAG = "fly/${this::class.simpleName}"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val imageView = findViewById<ImageView>(R.id.image)
GlideApp.with(this)
.load(R.mipmap.pic2)
.transform(RotateCircleCrop())
.override(500, 500)
.into(imageView)
}
inner class RotateCircleCrop : CircleCrop() {
override fun transform(
pool: BitmapPool,
toTransform: Bitmap,
outWidth: Int,
outHeight: Int
): Bitmap {
Log.d(TAG, "$outWidth $outHeight ${toTransform.byteCount}")
//先变换成圆形图。
val bmp = TransformationUtils.circleCrop(pool, toTransform, outWidth, outHeight)
//再逆向旋转30度。
return TransformationUtils.rotateImage(bmp, -30)
}
}
}
正常的摆放:
逆向旋转30度: