Skip to content

Instantly share code, notes, and snippets.

@LiewJunTung
Created July 11, 2019 16:27
Show Gist options
  • Save LiewJunTung/635c6c6a36653fc01d5a286a2873e0f1 to your computer and use it in GitHub Desktop.
Save LiewJunTung/635c6c6a36653fc01d5a286a2873e0f1 to your computer and use it in GitHub Desktop.
fun rotateBitmap(context: Context, bitmap: Bitmap): Bitmap{
val rs = RenderScript.create(context)
val allocation = Allocation.createFromBitmap(rs, bitmap)
val rotated = Allocation.createTyped(rs, Type.createXY(rs, Element.RGBA_8888(rs), bitmap.height, bitmap.width))
ScriptC_rotator(rs).apply {
_inImage = allocation
_inHeight = bitmap.height
_inWidth = bitmap.width
forEach_rotate_270_clockwise(rotated, rotated)
}
rs.destroy()
val bitmapImage = Bitmap.createBitmap(bitmap.height, bitmap.width, Bitmap.Config.ARGB_8888)
bitmapImage.copyPixelsFromBuffer(rotated.byteBuffer)
return bitmapImage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment