2012-05-03 7 views
0

シンプルなしわ修正のためのフラッシュアプ​​リケーションを構築する必要があります。ユーザーはポートレートの写真をアップロードし、しわのある領域を選択できるようになり、選択した部分にぼかしフィルタが適用されます。私の質問は、フリーフォーム領域にフィルタを適用することはどういうわけか可能ですか?私は選択を長方形にするのは簡単だろうが、実際には正しい領域をマークするのにはあまり役に立ちません。理想的には、ユーザーは領域のマーキングに使用する丸いブラシを入手し、「OK」を押してからフィルタを適用する必要があります。 これを行う方法はありますか?そして、あなたはこの仕事にどのように接近するかについてのいくつかのさらなる勧告を持っていますか? ActionScriptでビットマップデータを操作する経験はほとんどありません。フリーフォーム領域にぼかしフィルタを適用する

ご協力いただきましてありがとうございます。

Example of how what it should look like..

答えて

3

:-)事前に非常に多くのおかげで、次のようなアルゴリズムは、次のとおり

  1. BitmapData.draw()を使用して選択の形状のBitmapDataを作成
  2. が矩形片切断(Aがであるとします)選択領域で覆われている元の画像に、Bitmapdata.copyPixels()(Bとする)を使用して、ぼかし領域の余白を追加します。
  3. Aをソースビットマップとして使用して、BitmapData.threshold()の形Aで覆われていないBからすべてのピクセルを削除します。
  4. Bitmapdata.copyPixels()

を使用して画像を標的とするバック得られた画像

  • コピーぼやけたピクセルをぼかすここ完全かつ実施例です。
    解決策を見つけ出す際には、とにかくコードを書いています。
    うれしいですね。

    package 
    { 
        import flash.display.Bitmap; 
        import flash.display.BitmapData; 
        import flash.display.Loader; 
        import flash.display.Shape; 
        import flash.display.Sprite; 
        import flash.display.StageAlign; 
        import flash.display.StageScaleMode; 
        import flash.events.Event; 
        import flash.filters.BlurFilter; 
        import flash.geom.Matrix; 
        import flash.geom.Point; 
        import flash.geom.Rectangle; 
        import flash.net.URLRequest; 
        import flash.system.LoaderContext; 
    
        [SWF(width="800", height="600",backgroundColor="#FFFFFF")]  
        public class TestBlur extends Sprite 
        { 
         private const loader:Loader = new Loader(); 
    
         public function TestBlur() 
         { 
          stage.align = StageAlign.TOP_LEFT; 
          stage.scaleMode = StageScaleMode.NO_SCALE; 
    
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete); 
          loader.load(new URLRequest("http://i.stack.imgur.com/u3iEv.png"), new LoaderContext(true)); 
         } 
    
         protected function onLoadComplete(event:Event):void 
         { 
          trace(event); 
          var bmp:Bitmap = loader.content as Bitmap; 
          addChild(bmp); 
    
          // create some test selection area 
          var selection:Shape = new Shape(); 
          selection.graphics.lineStyle(30, 0xFF0000, .5); 
          selection.graphics.curveTo(75, -50, 200, 10); 
          selection.x = 40; 
          selection.y = 60; 
          addChild(selection); 
    
          // create a duplicate of the original image 
          var target:BitmapData = bmp.bitmapData.clone(); 
          var targetBmp:Bitmap = new Bitmap(target); 
          targetBmp.x = bmp.x + bmp.width; 
          addChild(targetBmp); 
    
          // 
          // *** main work starts here *** 
          // by now we have selection shape and a bitmap to blur 
    
          const destPoint:Point = new Point(); 
          const drawMatrix:Matrix = new Matrix(); 
          const blurMargin:uint = 10; 
          const blur:BlurFilter = new BlurFilter(2, 2, 3); 
          var rect:Rectangle; 
    
          // 0: prepare an image of selection area 
          // we'll need it at step 3 
          rect = selection.getBounds(selection); 
          rect.x -= blurMargin; 
          rect.y -= blurMargin; 
          rect.width += blurMargin*2; 
          rect.height += blurMargin*2;    
          var selectionImage:BitmapData = new BitmapData(rect.width, rect.height, true, 0); 
          drawMatrix.identity(); 
          drawMatrix.translate(-rect.x, -rect.y); 
          selectionImage.draw(selection, drawMatrix); 
    
            // just some testing 
            var test0:Bitmap = new Bitmap(selectionImage.clone()); 
            test0.y = bmp.y + bmp.height; 
            addChild(test0); 
    
          // 1: cut a rectangular piece of original image that is covered by selection area 
          rect = selection.getBounds(selection.parent); 
          rect.x -= blurMargin; 
          rect.y -= blurMargin; 
          rect.width += blurMargin*2; 
          rect.height += blurMargin*2; 
          var area:BitmapData = new BitmapData(rect.width, rect.height, true, 0); 
          area.copyPixels(bmp.bitmapData, rect, destPoint); 
    
            // just some testing 
            var test1:Bitmap = new Bitmap(area.clone()); 
            test1.y = bmp.y + bmp.height; 
            test1.x = test0.x + test0.width; 
            addChild(test1); 
    
          // 2: remove all pixels that are not covered by selection 
          area.threshold(selectionImage, area.rect, destPoint, "==", 0, 0, 0xFF000000); 
    
            // just some testing 
            var test2:Bitmap = new Bitmap(area.clone()); 
            test2.y = test0.y + test0.height; 
            test2.x = test0.x; 
            addChild(test2); 
    
          // 3: blur copied area 
          area.applyFilter(area, area.rect, destPoint, blur); 
    
            // just some testing 
            var test3:Bitmap = new Bitmap(area.clone()); 
            test3.y = test0.y + test0.height; 
            test3.x = test2.x + test2.width; 
            addChild(test3); 
    
          // 4: copy blurred pixels back to target image 
          destPoint.x = rect.x; 
          destPoint.y = rect.y; 
          target.copyPixels(area, area.rect, destPoint); 
         }   
        } 
    } 
    
  • 関連する問題