Created
July 11, 2019 16:27
-
-
Save LiewJunTung/635c6c6a36653fc01d5a286a2873e0f1 to your computer and use it in GitHub Desktop.
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
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