2012-05-03 2 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); 
         }   
        } 
    } 
    
  • 관련 문제