如何平滑使用 FileReference 加载的图像?

发布于 2024-08-24 15:52:03 字数 713 浏览 3 评论 0原文

一直试图平滑使用 FileReferece 加载的图像,但没有成功。下面是我正在使用的代码:

fileRef = new FileReference();
fileRef.addEventListener(Event.COMPLETE, fileLoaded);

private function fileLoaded(e:Event):void{
    var ldr:Loader = new Loader();             
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
        var bm:Bitmap = Bitmap(e.target.content as Bitmap);
        bm.smoothing = true;
        img.load(bm)
    }); 
    ldr.loadBytes(fileRef.data);
}   

<custom:SWFLoaderAdvanced id="img"/>

bm.smoothing 应该平滑加载的图像,但由于某种原因它没有。我在这里错过了什么吗?

注意:SWFLoaderAdvanced会自动平滑其中加载的所有图像。它可以完美地处理加载的图像,而不是使用 FileReference 加载的图像。

Been trying to smooth images loaded with FileReferece with no luck. Below is the code I'm using:

fileRef = new FileReference();
fileRef.addEventListener(Event.COMPLETE, fileLoaded);

private function fileLoaded(e:Event):void{
    var ldr:Loader = new Loader();             
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
        var bm:Bitmap = Bitmap(e.target.content as Bitmap);
        bm.smoothing = true;
        img.load(bm)
    }); 
    ldr.loadBytes(fileRef.data);
}   

<custom:SWFLoaderAdvanced id="img"/>

bm.smoothing should've smoothened the loaded image, but for some reason it doesn't. Am I missing something here?

Note: SWFLoaderAdvanced automatically smoothens any image that's loaded inside it. It works perfectly with loaded images other than the ones loaded with FileReference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯沦落人 2024-08-31 15:52:03

我相信数据作为 byteArray 加载到闪存中,尝试一下,看看会发生什么。

您的线路:

var bm:Bitmap = Bitmap(e.target.content as Bitmap);

想要成为:

var bm:Bitmap = new Bitmap(e.target.content as BitmapData);

I believe that the data is loaded into flash as byteArray, try this and see what happens.

your line here:

var bm:Bitmap = Bitmap(e.target.content as Bitmap);

wants to be:

var bm:Bitmap = new Bitmap(e.target.content as BitmapData);
枕梦 2024-08-31 15:52:03

我不确定为什么 bm.smoothing 不起作用,也许可以,但效果几乎不明显。您可以尝试的一件事是 BlurFilter

import flash.filters.BlurFilter;
var blur:BlurFilter = new BlurFilter(1, 1, 5);

其中第一个和第二个参数是 blurXblurY,第三个参数是质量。我想您可以将其应用于 Bitmap 对象,可能使用此函数:

bitmapDataObject.applyFilter();

该函数在 AS3 Reference 中有进一步详细说明;我的计算机上没有安装 Flash,所以我无法准确测试它是如何工作的。不过,您肯定能够对 Bitmap 对象应用模糊效果,并且如果您以高质量进行非常轻微的模糊效果,它看起来会平滑图像。查看文档中的 BlurFilterBitmapData

希望这有帮助!

I'm not sure why bm.smoothing isn't working, perhaps it is but the effect is barely noticeable. One thing you could try is a BlurFilter.

import flash.filters.BlurFilter;
var blur:BlurFilter = new BlurFilter(1, 1, 5);

Where the first and second arguments are blurX and blurY, and the third is the quality. I imagine you can apply this to a Bitmap object, probably using this function:

bitmapDataObject.applyFilter();

That function is detailed further in the AS3 Reference; I'm not at a computer with Flash installed so I can't test exactly how this would work. You will definitely be able to apply blur effects to Bitmap objects though, and if you do a very slight one with high quality, it'll appear to smooth the image. Check out BlurFilter and BitmapData in the docs.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文