2010-06-23 126 views
2

我正在构建一个投资组合站点,当用户单击一个thumnail时动态加载大量高分辨率图像。但是,在调整大小以适应当前浏览器时,我在维护原始图像质量时遇到问题。使用as3调整图片大小

目前我只是调整宽度&高度属性的图像宽度到舞台按比例,这是工作正常让它适合,但我想不出如何保持图像质量?我是否需要将它作为位图加载并重绘/平滑或类似?

这是我目前正在使用适当的代码:

var req:URLRequest = new URLRequest("images/101.jpg"); 
var loader:Loader = new Loader(); 

var widthRatio:Number; 
var heightRatio:Number; 

function imageLoaded(e:Event):void 
{ 
//add image to stage 
addChild(loader); 


// resize proportionally 
if (loader.width > stage.stageWidth){ 
    widthRatio=loader.width/stage.stageWidth; 
    trace(widthRatio) 
    trace(loader.width); 
} 
if (loader.height > stage.stageHeight){ 
    heightRatio=loader.height/stage.stageHeight; 
    trace(heightRatio) 
    trace(loader.height) 
} 

if (widthRatio > heightRatio){ 
    loader.width = stage.stageWidth; 
    loader.height = loader.height/widthRatio; 
} else { 
    loader.height = stage.stageHeight; 
    loader.width = loader.width/heightRatio; 
} 

//centre on stage 
loader.x=stage.stageWidth/2 - loader.width/2; 
loader.y=stage.stageHeight/2 - loader.height/2; 

} 

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); 
loader.load(req); 

回答

6

看一看Bitmap smoothing

您的Loader将有一个content property这将是一个Bitmap。将其设置为smoothing为true。

function imageLoaded(e:Event):void 
{ 
    //add image to stage 
    addChild(loader); 
    Bitmap(loader.content).smoothing = true; 

    // ... 

它使图像有点模糊,但它在大多数情况下是一个重大改进。

+0

认为这肯定有一个简单的解决办法,似乎无法找到它虽然。谢谢! – swanny 2010-06-24 02:04:16

+0

ha另一个我为什么讨厌flash的原因 – samccone 2012-01-21 17:23:41