动作:调整大小的BitmapData平滑 [英] Actionscript: resizing bitmapdata with smoothing
问题描述
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
有问题的图像缩放。看起来平滑不工作或者有某种东西在code失踪。也许矩阵应该有更多的东西?
Having problem with images resizing. Looks like smoothing is not working or something is missing in the code. Maybe Matrix should have something more?
原图:
http://imageshack.us/a/img28/4784/dc7f2ec4b0f3323cdc4e01e.jpg
和它的结果是:
http://imageshack.us/a/img855/4784/dc7f2ec4b0f3323cdc4e01e.jpg
我可以链接一群人的图像。一些奇怪的像素配置存在。 它可以以某种方式解决吗?
I can link a bunch of others images. Some strange pixel disposition exist. Can it be fixed somehow?
我测试JPEG质量100%和stage.quality ='最好的',但他们没有给出所需的质量结果。
I have tested jpeg quality 100% and stage.quality='best', but none of them give the required quality outcome.
推荐答案
看来,画上的BitmapData对BitmapData时,你的问题是最近采样模式。或许下面可能会有帮助:
It seems that your problem is "nearest" sampling mode when drawing a BitmapData over a BitmapData. Perhaps the following might help:
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
适用如果形状添加到舞台(顺便说一句,您可以使用形状来显示上传的PIC,然后绘制过的BitmapData以节省。 )但是,这可能无法正常工作 - 我现在不能测试这一权利
Using Flash's native graphics renderer will most likely perform at least a bilinear interpolation on a drawn bitmap, which seemingly is your desired result. Also, stage.quality
applies if that shape is added to stage (BTW, you can use the shape to display an uploaded pic, then draw over a BitmapData in order to save.) But, this might not work - I can't test this right now.
这篇关于动作:调整大小的BitmapData平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!