2013-03-14 29 views
0
var bd:BitmapData=new BitmapData(file.width,file.height); 
bd.setPixels(new Rectangle(0,0,file.width,file.height),file.raw); 

var scale_x_percents:Number = (w/bd.width); 
var scale_y_percents:Number = (h/bd.height); 
if(!stretch) { 
    if(bd.width*scale_y_percents>=w) { 
     scale_x_percents=scale_y_percents; 
    } 
    else if(bd.height*scale_x_percents>=h) { 
     scale_y_percents=scale_x_percents; 
    } 
} 
var matrix:Matrix = new Matrix(); 
matrix.scale(scale_x_percents,scale_y_percents); 

var resizedBd:BitmapData = new BitmapData(Math.floor(bd.width*scale_x_percents), Math.floor(bd.height*scale_y_percents), true, 0x000000); 
resizedBd.draw(bd, matrix, null, null, null, true); // true is smoothing option, it will blur sharpened pixels 

在調整圖像大小時遇到​​問題。看起來像平滑不工作或代碼中缺少的東西。也許矩陣應該有更多的東西?Actionscript:使用平滑調整位圖數據大小

原圖:

http://imageshack.us/a/img28/4784/dc7f2ec4b0f3323cdc4e01e.jpg

,它的結果是:

http://imageshack.us/a/img855/4784/dc7f2ec4b0f3323cdc4e01e.jpg

我可以鏈接一羣人的圖像。一些奇怪的像素配置存在。 它可以以某種方式修復嗎?

我測試了jpeg質量100%和stage.quality ='最佳',但沒有一個提供所需的質量結果。

+0

有人嗎?任何提示都可以。 – Somebody 2013-03-14 12:27:11

+0

它對我來說工作正常,而且你的代碼似乎沒問題......不知道該怎麼告訴你(因爲這不應該受平臺或任何其他場景或外部配置的影響)。你確定要添加正確的BitmapData到舞臺嗎? – Cay 2013-03-17 14:13:27

+0

BitmapData是從Loader對象中選取的。來自用戶機器。 – Somebody 2013-03-17 17:51:41

回答

4

當通過BitmapData繪製BitmapData時,您的問題似乎是「最接近」採樣模式。也許下面可能會有幫助:

var sh:Shape=new Shape(); 
sh.graphics.beginBitmapFill(bd,matrix,false,true); 
sh.graphics.lineStyle(0,0,0); // no lines border this shape 
sh.graphics.drawRect(0,0,resizedBD.width,resizedBD.height); 
sh.graphics.endFill(); 
resizedBD.draw(sh); // or with smoothing on 

使用Flash的原生圖形渲染器將在繪製位圖,這似乎是你想要的結果最有可能至少執行雙線性插值。另外,stage.quality適用如果該形狀被添加到階段(順便說一句,您可以使用形狀顯示上傳的圖片,然後繪製一個BitmapData以保存。)但是,這可能無法正常工作 - 我無法測試這個權利現在。

+0

好的,謝謝我很快就會對此進行測試。 – Somebody 2013-03-18 12:58:11

+0

它的工作!該死的。這個解決方案背後隱藏着什麼魔力? :)我的知識必須填補這個空白。 :D – Somebody 2013-03-18 13:46:57

+0

這是新的樣品。你可以將它與舊的進行比較。 http://img832.imageshack.us/img832/2591/ed4cfedff10d978a5b85e3c.jpg 再次感謝! :) – Somebody 2013-03-18 13:48:17