我使用AS2将一些图像从外部站点动态导入到SWF中。当我从我的计算机加载我的图像时,它工作得很好,但当我试图从外部服务器加载它们时,平滑不起作用。
我的代码:
var imageLoad:MovieClipLoader = new MovieClipLoader();
imageLoad.addListener({
onLoadInit:function (target:MovieClip) {
target._quality = "BEST";
target._width = 160;
target._yscale = target._xscale;
if (target._height>105) {
target._height = 105;
target._xscale = target._yscale;
}
target.forceSmoothing = true;
}
});
imageLoad.loadClip(imageURL,imageMC);我已经在网上尝试了我能找到的每一个解决方案,但没有人使用平滑...
有什么解决方案吗?
发布于 2009-09-04 06:28:17
AS2...啊..。记忆(更像是噩梦)。
试试我的“老好人”BitmapLoader.as吧。我已经使用它很多年了,从来没有让我失望过……它写得不漂亮,里面有一些双重作用域设置器……但我不在乎。它很老了,而且它已经完美地完成了它的工作(总是!)。它在构造函数中需要一个布尔值,用于将平滑设置为true或false
import flash.display.BitmapData;
class BitmapLoader extends Object {
private var mLoader : MovieClipLoader;
private var scope : Object;
private var _mc : MovieClip;
private var _url : String;
private var _func : Object;
private var smooth : Boolean;
public function BitmapLoader(smooth : Boolean)
{
this.smooth = smooth;
mLoader = new MovieClipLoader( );
addListener( this );
}
public function addListener(inListener : Object) : Void
{
mLoader.addListener( inListener );
scope = inListener;
}
public function removeListener(inListener : Object) : Void
{
mLoader.removeListener( inListener );
}
private function onLoadInit(inTarget : MovieClip) : Void
{
var bitmap : BitmapData = new BitmapData( inTarget._width, inTarget._height, true, 0x000000 );
bitmap.draw( inTarget );
var parent : MovieClip = inTarget._parent;
var img : MovieClip = parent.createEmptyMovieClip( "imageloader_smooth_mc", parent.getNextHighestDepth( ) );
inTarget.unloadMovie( );
inTarget.removeMovieClip( );
delete inTarget;
img.attachBitmap( bitmap, img.getNextHighestDepth( ), "never", true );
scope[_func]( img );
}
private function onLoadError(errorCode : String, httpStatus : Number) : Void
{
error( errorCode, httpStatus );
}
/**
* loadBitmap( http://www.test.nl/img.jpg, movieclip, "dothis");
*/
public function loadBitmap(url : String, mc : MovieClip, func : Object) : Void
{
_url = url;
_mc = mc;
_func = func;
var raw : MovieClip = _mc.createEmptyMovieClip( "imageloader_raw_mc", _mc.getNextHighestDepth( ) );
mLoader.loadClip( _url, raw );
}
private function error(errorCode : String, httpStatus : Number) : Void
{
var raw : MovieClip = _mc.createEmptyMovieClip( "imageloader_raw_mc", _mc.getNextHighestDepth( ) );
mLoader.loadClip( "img/notfound.jpg", raw );
};
}您可以像这样使用这个类:
var loader : BitmapLoader = new BitmapLoader( true );
loader.addListener( this );
loader.loadBitmap( "http://test.nl/example.jpg", this, "doneLoading" );‘'true’是平滑布尔值,addListener(这)是为了防止作用域问题(AS2-bleeh),"doneLoading“是它在加载完成时调用的函数名。
希望这对你有用。
祝好运!
发布于 2009-09-03 22:51:32
不确定,但您的问题似乎是跨域问题的症状。如果加载的SWF源自其它域,则您将无法修改该SWF属性(在此情况下为平滑),除非跨域策略文件允许这样做。
如果这不是问题所在,我记得从根本上绘制bitmapData总是起到了很大的作用。如果结果是一个黑色图像,那么你很确定有一个跨域的问题。这篇文章为AS2精确地解释了这项技术:
http://www.kaourantin.net/2005/12/dynamically-loading-bitmaps-with.html
发布于 2009-09-09 06:16:14
如何使用缩放矩阵将其绘制在另一个BitmapData上?我听说它会比缩放位图本身更平滑…
下面的代码来自here。
// source in this example is a DisplayObject
var temp:BitmapData = new BitmapData( sourceWidth, sourceHeight );
temp.draw( source );
var output:BitmapData = new BitmapData( outputWidth, outputHeight );
var matrix:Matrix = new Matrix();
matrix.scale( outputWidth / sourceWidth, outputHeight / sourceHeight );
output.draw( temp, matrix, null, null, null, true );
temp.dispose();https://stackoverflow.com/questions/1376182
复制相似问题