4
Flexで画像(またはFXG)を歪めたい。Flexでイメージ(またはFXG)を歪める方法は?
基本的には、下の画像のように画像のエッジを修正したいだけです。私は単純な歪みを作る方法を知っていますが、その方法を見つけることはできません。
Flexで画像(またはFXG)を歪めたい。Flexでイメージ(またはFXG)を歪める方法は?
基本的には、下の画像のように画像のエッジを修正したいだけです。私は単純な歪みを作る方法を知っていますが、その方法を見つけることはできません。
の答えは、あなたがDisplacementMapFilter
で必要なもの...正しかったです!
displacementImageは、一般に灰色であるべきである - これ>は歪みがないことを意味し、それぞれの下部および上部edgelikeに白とグレーの半径方向勾配を追加する:
地図では、次のようになります。
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);
}
}
}
[DisplacementMapFilter](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filters/DisplacementMapFilter.html) –
を使用して画像を歪ませてください。 [これは役立つかもしれません](http://www.emanueleferonato.com/2007/12/03/understanding-flash-displacement-map-filter/) – keyle