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

标签 apache-flex image distortion morphing

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

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

enter image description here

最佳答案

答案是正确的...您需要的是一个 DisplacementMapFilter !!

置换图像一般应该是灰色的 -> 表示没有失真,并为每个上下边缘添加一个白色和一个灰色的径向渐变,如下所示:

Distortion map for this very effect

The image i used to be distortet

Final result after distortion

使用 Map 你可以这样:

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);
        }
    }
}

关于apache-flex - 如何在 Flex 中扭曲图像(或 FXG)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8414682/

相关文章:

Flash Builder 4 突然停止对某些类进行自动完成

java - 在 Android 中显示来自休息服务器的 gif/动画 ImageView

c++ - OpenCV 重新映射裁剪我的风景图像

android - 更改图像某些部分的颜色

android - 混合两个音频缓冲区时的咔嗒声/失真

javascript - JavaScript 中的图像失真算法

php - 将位图数据从 Flex 发送到 Php

apache-flex - 在tomcat上部署flex

apache-flex - 添加 mouseOver/mouseDown/mouseUp/等。自定义 MXML 组件

ios - Nativescript-Vue -- 本地镜像路径不起作用