问:最近做了一个Flash的电子相册,碰到一个很棘手的问题,就是通过AS动态载入的图片在缩放的时候出现模糊和锯齿,由于这些位图是通过AS从外部载入进来的,不能在Flash制作时通过修改库里图片的属性来消除锯齿。所以求一个解决之法,小弟在此不胜感激了。
ycccc8202
(春叶飘零) 答:外部加载的可以通过bitmap来进行解决。主要用到MovieClip.attachBitmap中的一个smooth参数的设置,来进行平滑处理。
/*****进行消锯齿与不消锯齿的对比*****/
import flash.display.BitmapData;
/*************加载******************/
var container1:MovieClip = createEmptyMovieClip("container1", getNextHighestDepth());
var container2:MovieClip = createEmptyMovieClip("container2", getNextHighestDepth());
var loader1:MovieClipLoader = new MovieClipLoader();
var loader2:MovieClipLoader = new MovieClipLoader();
var obj:Object = new Object();
obj.onLoadInit = function(target:MovieClip) {
trace("onLoadInit");
loaderDispose(target);
};
loader1.addListener(obj);
loader1.loadClip("1.jpg", container1);
loader2.addListener(obj);
loader2.loadClip("1.jpg", container2);
/**********图片处理***************/
var bitmapLoader1:MovieClip = createEmptyMovieClip("Bloader1", getNextHighestDepth());
var bitmapLoader2:MovieClip = createEmptyMovieClip("Bloader2", getNextHighestDepth());
var bitmap1:BitmapData;
var bitmap2:BitmapData;
function loaderDispose(mc:MovieClip) {
mc._visible = false;
/*******不平滑*******/
if (mc._name == "container1") {
bitmap1 = new BitmapData(mc._width, mc._height, true, 0x00FFFFFF);
bitmap1.draw(mc);
bitmapLoader1.attachBitmap(bitmap1, 0);
bitmapLoader1._x = -50;
bitmapLoader1._xscale = bitmapLoader1._yscale=250;
} else {
/******平滑处理*******/
bitmap2 = new BitmapData(mc._width, mc._height, true, 0x00FFFFFF);
bitmap2.draw(mc);
bitmapLoader2.attachBitmap(bitmap2, 1, "auto", true);
//主要就是这个smooth参数,true表示平滑
bitmapLoader1._x = -50;
bitmapLoader2._y = 300;
bitmapLoader2._xscale = bitmapLoader2._yscale=250;
}
}