Skip to content

Instantly share code, notes, and snippets.

@marchbold
Last active August 29, 2015 13:57
Show Gist options
  • Save marchbold/9905568 to your computer and use it in GitHub Desktop.
Save marchbold/9905568 to your computer and use it in GitHub Desktop.
Rotate a bitmap data to account for image orientation
function applyOrientation( bitmapData:BitmapData, orientation:String ) :BitmapData
{
/*
1) transform="";;
2) transform="-flip horizontal";;
3) transform="-rotate 180";;
4) transform="-flip vertical";;
5) transform="-transpose";;
6) transform="-rotate 90";;
7) transform="-transverse";;
8) transform="-rotate 270";;
*/
var w:int = bitmapData.width;
var h:int = bitmapData.height;
var scaleX:Number = 1;
var scaleY:Number = 1;
var rotateAngle:Number = 0;
switch (orientation)
{
default:
case "1":
break;
case "2":
scaleX = -1;
break;
case "3":
rotateAngle = Math.PI;
break;
case "4":
scaleY = -1;
break;
case "5":
break;
case "6":
w = bitmapData.height;
h = bitmapData.width;
rotateAngle = Math.PI / 2;
break;
case "8":
w = bitmapData.height;
h = bitmapData.width;
rotateAngle = -Math.PI / 2;
break;
}
var matrix:Matrix = new Matrix();
matrix.translate( - bitmapData.width * 0.5, - bitmapData.height * 0.5 );
matrix.scale( scaleX, scaleY );
matrix.rotate( rotateAngle );
matrix.translate( w * 0.5, h * 0.5 );
var result:BitmapData = new BitmapData( w, h );
result.draw( bitmapData, matrix );
return result;
}
// com.distriqt.Camera
@marchbold
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment