如何平滑使用 FileReference 加载的图像?
一直试图平滑使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信数据作为 byteArray 加载到闪存中,尝试一下,看看会发生什么。
您的线路:
想要成为:
I believe that the data is loaded into flash as byteArray, try this and see what happens.
your line here:
wants to be:
我不确定为什么 bm.smoothing 不起作用,也许可以,但效果几乎不明显。您可以尝试的一件事是
BlurFilter
。其中第一个和第二个参数是
blurX
和blurY
,第三个参数是质量。我想您可以将其应用于Bitmap
对象,可能使用此函数:该函数在 AS3 Reference 中有进一步详细说明;我的计算机上没有安装 Flash,所以我无法准确测试它是如何工作的。不过,您肯定能够对 Bitmap 对象应用模糊效果,并且如果您以高质量进行非常轻微的模糊效果,它看起来会平滑图像。查看文档中的
BlurFilter
和BitmapData
。希望这有帮助!
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 aBlurFilter
.Where the first and second arguments are
blurX
andblurY
, and the third is the quality. I imagine you can apply this to aBitmap
object, probably using this function: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 outBlurFilter
andBitmapData
in the docs.Hope this helps!