2010-02-10 44 views

回答

0

在Flex可以使用图像处理来实现所期望的效果 - 参见http://www.insideria.com/2008/03/image-manipulation-in-flex.html

private var original:BitmapData; 
private static const MAX_WIDTH:uint = 2880; 
private static var MAX_HEIGHT:uint = 2880; 


private function loadImage(url:String):void 
{ 
var request:URLRequest = new URLRequest(url); 

    var imageLoader:Loader = new Loader(); 
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_completeHandler); 
    // add other listeners here 
    imageLoader.load(request) 
} 

private function image_completeHandler(event:Event):void 
{ 
    var bmd:BitmapData = Bitmap(event.currentTarget.content).bitmapData; 

    var originalWidth:Number = bmd.width; 
    var originalHeight:Number = bmd.height; 
    var newWidth:Number = originalWidth; 
    var newHeight:Number = originalHeight; 

    var m:Matrix = new Matrix(); 

    var scaleX:Number = 1; 
    var scaleY:Number = 1; 

    if (originalWidth > MAX_WIDTH || originalHeight > MAX_HEIGHT) 
    { 
     sx = MAX_WIDTH/originalWidth; 
     sy = MAX_HEIGHT/originalHeight; 
     var scale:Number = Math.min(sx, sy); 
     newWidth = originalWidth * scale; 
     newHeight = originalHeight * scale; 
    } 
    m.scale(scale, scale); 
    original = new BitmapData(newWidth, , newHeight); 

    original.draw(bmd, m); 

} 

旋转 要使用矩阵来旋转你要么创建具有适当参数

var q:Number = 30 * Math.PI/180 // 30 degrees in radians 

var m:Matrix = new Matrix(Math.cos(q), Math.sin(q), -1 * Math.sin(q), Math.cos(q)); 

//or as a shortcut use the rotate method 

var m:Matrix = new Matrix(); 

m.rotate(q) ; 
一个新矩阵的图像

当您在Flash Player中旋转某些内容时,它将围绕其注册点旋转。这是默认情况下的左上角。如果你想围绕不同的点旋转它,你需要将它向负方向偏移,做旋转,然后把它放回原来的位置。

var m:Matrix = new Matrix(); 

// rotate around the center of the image 

var centerX:Number = image.width/2; 

var centerY:Number = image.height /2; 

m.translate(-1 * centerX, -1 * centerY); 

m.rotate(q); 

m.translate(centerX, centrerY); 

翻转 要翻转和图像是2步过程。第一步是将当前的scaleX和/或scaleY乘以-1,第二步是调整x和y的位置。当您翻转并成像时,注册点不会改变,并且其绘制方向相反。为了弥补你需要改变x位置的宽度和y位置的高度。

var m:Matrix = new Matrix(); 

m.scale(-1, 0); // flip horizontal assuming that scaleX is currently 1 

m.translate(image.width, 0); // move its x position by its width to put it in the upper left corner again 
相关问题