如何在 Flex 中扭曲图像(或 FXG)?

发布于 2024-12-19 21:03:58 字数 148 浏览 1 评论 0 原文

我想在 Flex 中扭曲图像(或 FXG)。

基本上只是想修改图像的边缘,如下图所示。我知道如何进行简单的扭曲,但我找不到方法。

在此处输入图像描述

I want to distort images (or FXGs) in Flex.

Basically just want to modify the edges of an image like the image below. I know how to make simple distortions but I can't find a way of doing that.

enter image description here

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

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

发布评论

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

评论(1

静若繁花 2024-12-26 21:03:58

答案是正确的...您需要的是 DisplacementMapFilter

一般情况下displacementImage应该是灰色的->意味着没有失真,并为每个下边缘和上边缘添加白色和灰色径向渐变,如下所示:

这种效果的扭曲贴图

我曾经扭曲的图像

使用地图,您将像这样:

package {
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.DisplacementMapFilter;
    import flash.filters.DisplacementMapFilterMode;
    import flash.geom.Point;
    import flash.net.URLRequest;

    public class DistortImage extends Sprite
    {

        private var sourceImage:Loader;
        private var distortMap:Loader;

        public function DistortImage()
        {
            super();


        // Loading the Image to be distorted
            sourceImage = new Loader();
            var requ: URLRequest = new URLRequest("text.jpg");
            sourceImage.contentLoaderInfo.addEventListener(Event.COMPLETE, loadMap);
            sourceImage.load(requ);
        }

        private function loadMap( E:Event = null ):void{

        // loading distortion map ( grayscale )
            distortMap = new Loader();
            var requ: URLRequest = new URLRequest("distortMap.jpg");
            distortMap.contentLoaderInfo.addEventListener(Event.COMPLETE, applyDistortion);
            distortMap.load(requ);
        }
        private function applyDistortion( E:Event = null ):void{

        // get jpg as BitmapData
            var bmpData:BitmapData = new BitmapData( distortMap.content.width,distortMap.content.height);
            bmpData.draw(distortMap);

        // create the filter - notice gray(128,128,128) means no distortion white is negative black is positive distortion
            var offsetOfMap:Point = new Point(0,0);
            var redChannelCode:uint = BitmapDataChannel.RED; // is not important cause you just need oneway distortion 
            var yDistortion:int = 20; // strength

            var distortFilter:DisplacementMapFilter = new DisplacementMapFilter(bmpData,offsetOfMap,0,redChannelCode,0,yDistortion,DisplacementMapFilterMode.COLOR,0xffffff,0);

        // filters need to be included in an array to add on display Object
            var filters:Array = new Array();
            filters.push(distortFilter);

        // adding filter to image
            sourceImage.filters = filters;
            addChild(sourceImage);
        }
    }
}

The answers were right... what you need is a DisplacementMapFilter!!

The displacementImage should be grey in general -> means no distortion, and add a white and a gray radial gradient to each lower and upper edgelike this:

Distortion map for this very effect

The image i used to be distortet

Final result after distortion

And with the Map you go like this:

package {
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.DisplacementMapFilter;
    import flash.filters.DisplacementMapFilterMode;
    import flash.geom.Point;
    import flash.net.URLRequest;

    public class DistortImage extends Sprite
    {

        private var sourceImage:Loader;
        private var distortMap:Loader;

        public function DistortImage()
        {
            super();


        // Loading the Image to be distorted
            sourceImage = new Loader();
            var requ: URLRequest = new URLRequest("text.jpg");
            sourceImage.contentLoaderInfo.addEventListener(Event.COMPLETE, loadMap);
            sourceImage.load(requ);
        }

        private function loadMap( E:Event = null ):void{

        // loading distortion map ( grayscale )
            distortMap = new Loader();
            var requ: URLRequest = new URLRequest("distortMap.jpg");
            distortMap.contentLoaderInfo.addEventListener(Event.COMPLETE, applyDistortion);
            distortMap.load(requ);
        }
        private function applyDistortion( E:Event = null ):void{

        // get jpg as BitmapData
            var bmpData:BitmapData = new BitmapData( distortMap.content.width,distortMap.content.height);
            bmpData.draw(distortMap);

        // create the filter - notice gray(128,128,128) means no distortion white is negative black is positive distortion
            var offsetOfMap:Point = new Point(0,0);
            var redChannelCode:uint = BitmapDataChannel.RED; // is not important cause you just need oneway distortion 
            var yDistortion:int = 20; // strength

            var distortFilter:DisplacementMapFilter = new DisplacementMapFilter(bmpData,offsetOfMap,0,redChannelCode,0,yDistortion,DisplacementMapFilterMode.COLOR,0xffffff,0);

        // filters need to be included in an array to add on display Object
            var filters:Array = new Array();
            filters.push(distortFilter);

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