将模糊过滤器应用于

将模糊过滤器应用于

本文介绍了将模糊过滤器应用于 BitmapData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来使用 BitmapData 模糊图像的代码.在 Slider_changeHandler(event:Event):void 事件上调用该函数,并将滑块的值作为模糊值传递给该函数.

Here's the code I am using to blur an image using BitmapData. The function is called on a Slider_changeHandler(event:Event):voidevent and the value of the slider is passed to the function as blurvalue.

问题是该函数有效,但似乎是累积性的(如果这是正确的词!),也就是说,假设我将它滑动到最大,然后尝试通过将其向后滑回模糊的前面来减少模糊还在不断增加.我如何使它工作,以便向上滑动时模糊增加,向后滑动时模糊减少,当滑块为 0 时,不应用模糊.

The problem is the function works but seems to be cummalative (if that's the correct word!), that is, suppose I slide it to the maximum and after that try to reduce the blur by sliding it back towards the front the blur still keeps increasing. How do I make it to work so when I will slide it up blur increases and when I slide it back blur decreases and when slider is at 0, no blur is applied.

            var blur:BlurFilter = new BlurFilter();
            blur.blurX = blurvalue;
            blur.blurY = blurvalue;
            blur.quality = BitmapFilterQuality.MEDIUM;
            bitmapdata.applyFilter(bitmapdata,new
                Rectangle(0,0,bitmapdata.width,bitmapdata.height),new Point(0,0),
                blur);
            return bitmapdata;

推荐答案

如何返回应用了过滤器的原始 bitmapData 的克隆?

how about returning a clone of the original bitmapData with the filter applied ?

例如

var result:BitmapData = bitmapdata.clone();
var blur:BlurFilter = new BlurFilter();
blur.blurX = blurvalue;
blur.blurY = blurvalue;
blur.quality = BitmapFilterQuality.MEDIUM;
result.applyFilter(result,new
Rectangle(0,0,bitmapdata.width,bitmapdata.height),new Point(0,0),blur);
return result;

此外,如果您正在使用 BlurFilter,您可能需要一个更大的矩形,具体取决于模糊量.为此,您可以使用 generateFilterRect() 方法来为过滤器获取正确大小的矩形.

Also, if you're using the BlurFilter, you might need a larger rectangle, depending on the amount of blur. For that, you can use the generateFilterRect() method to get correct sized rectangle for the filter.

这篇关于将模糊过滤器应用于 BitmapData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:22