凡人而已。

导航

Bitmap的翻转函数

/*

   对bitmap的bitmapData进行0,90,180,-90四个方向进行翻转

 接受参数  bitmapdata

 返回 bitmapdata

 摘自wayne23的博客

*/

/**垂直翻转*/
public static function upanddown(bt:BitmapData):BitmapData
{
    var bmd:BitmapData = new BitmapData(bt.width, bt.height, true, 0x00000000);
    for (var xx:int=0; xx<bt.width; xx++)
    {
        for (var yy:int=0; yy<bt.height; yy++)
        {
            bmd.setPixel32(xx, bt.height-yy-1, bt.getPixel32(xx,yy));
        }
    }
    return bmd;
}

/**水平翻转*/        
public static function rightandleft(bt:BitmapData):BitmapData
{
    var bmd:BitmapData = new BitmapData(bt.width, bt.height, true, 0x00000000);
    for (var yy:int=0; yy<bt.height; yy++)
    {
        for (var xx:int=0; xx<bt.width; xx++)
        {
            bmd.setPixel32(bt.width-xx-1, yy, bt.getPixel32(xx,yy));
        }
    }
    return bmd;
}

/**90翻转*/        
public static function turn90(bt:BitmapData):BitmapData
{
    var bmd:BitmapData = new BitmapData(bt.height, bt.width, true, 0x00000000);
    for (var yy:int=0; yy<bt.height; yy++)
    {
        for (var xx:int=0; xx<bt.width; xx++)
        {
            bmd.setPixel32(yy,bt.width-xx, bt.getPixel32(xx,yy));
        }
    }
    return bmd;
}

/**270翻转*/
public static function turn270(bt:BitmapData):BitmapData
{
    var bmd:BitmapData = new BitmapData(bt.height, bt.width, true, 0x00000000);
    for (var yy:int=0; yy<bt.height; yy++)
    {
        for (var xx:int=0; xx<bt.width; xx++)
        {
            bmd.setPixel32(bt.height-yy-1,bt.width-xx, bt.getPixel32(xx,yy));
        }
    }
    return bmd;
}

posted on 2013-08-08 20:25  凡人而已。  阅读(735)  评论(0)    收藏  举报