2011-02-07 25 views
1

enter image description here如何用actionscript創建一個很好的「草圖」效果?

我已經能夠得到一個素描效果(在某種程度上)可使用Pixel Bender着色器的位置:Adobe Pixel Bender。正下方示例照片(帶有令人毛骨悚然的眼睛)。

右上方的圖像是用Balsamiq模型創建的,是照片 - 素描效果的很好例子。那麼我該如何創建這樣的東西呢?任何鏈接或源代碼表示讚賞。

+1

Flash有能力在swf中運行Pixel Bender過濾器。這裏有一個關於如何做的很好的基本教程。 http://www.gotoandlearn.com/play.php?id=83 – StapleGun

+0

@StapleGun:我知道PB,並用它來創造右下角的效果。但它不夠好,所以我正在尋找其他一些可以在右上角實現效果的濾鏡。 – Yeti

回答

6

sketch filter

頂部圖形是通過用下面的代碼和底部的圖片閃光產生是我理解應該是目標。他們不完全一樣,但有點接近。

結果高度依賴於在源圖像上執行的微調(//去飽和度+亮度+對比度),我不認爲它可以在一系列圖片上自動執行。

package 
{ 
import flash.display.Bitmap; 
import flash.display.BitmapData; 
import flash.display.BlendMode; 
import flash.display.Sprite; 
import flash.filters.ColorMatrixFilter; 
import flash.filters.ConvolutionFilter; 
import flash.geom.ColorTransform; 
import flash.geom.Matrix; 
import flash.geom.Point; 
/** 
* @author Nicolas Barradeau 
* http://en.nicoptere.net 
*/ 
public class Sketch extends Sprite 
{ 
    [Embed(source = '../lib/test.jpg')]private var src:Class; 
    private var bd:BitmapData = new src().bitmapData; 
    public function Sketch() 
    { 
     addChild(new Bitmap(bd));//need a bitmapData called bd 
     sketch(bd); 
    } 

    private function sketch(bd:BitmapData):void 
    { 

     // desaturation + brightness + contrast 
     bd.applyFilter(bd, bd.rect, new Point, grayscale); 
     bd.applyFilter(bd, bd.rect, new Point,brightness(25)); 
     bd.applyFilter(bd, bd.rect, new Point,contrast(20)); 
     bd.applyFilter(bd, bd.rect, new Point,brightness(35)); 

     //creates the outlines 
     var outlines:BitmapData = bd.clone(); 
     outlines.applyFilter(outlines, outlines.rect, new Point, outline(80)); 
     outlines.applyFilter(outlines, outlines.rect, new Point, negative); 
     outlines.applyFilter(outlines, outlines.rect, new Point, grayscale); 

      //draws the outlines into the bd 
      bd.draw(outlines, new Matrix(1, 0, 0, 1), new ColorTransform(1, 1, 1, .75), BlendMode.MULTIPLY); 

     //creates some additionnal noise 
     var noise:BitmapData = bd.clone(); 
     noise.noise(0, 0, 255, 7, true); 

      //draws the extra noise 
      bd.draw(noise, new Matrix(1, 0, 0, 1), new ColorTransform(1, 1, 1, 0.15), BlendMode.ADD); 

     //final contrast pass 
     bd.applyFilter(bd, bd.rect, new Point, contrast(55)); 

    } 

    private function outline(value:Number = 80):ConvolutionFilter 
    { 
     var q:Number = value/4; 
     return new ConvolutionFilter( 3, 3, [ 
               0 , q , 0 , 
               q , -value , q , 
               0 , q , 0 
               ], 10); 
    } 

    private function get negative():ColorMatrixFilter 
    { 
     return new ColorMatrixFilter( [ 
              -1 , 0 , 0 , 0 , 0xFF, 
              0 , -1 , 0 , 0 , 0xFF, 
              0 , 0 , -1 , 0 , 0xFF, 
              0 , 0 , 0 , 1 , 0 
             ] ); 
    } 

    private function get grayscale():ColorMatrixFilter 
    { 
     return new ColorMatrixFilter( [ 
              .3086 , .6094 , .0820 , 0 , 0, 
              .3086 , .6094 , .0820 , 0 , 0, 
              .3086 , .6094 , .0820 , 0 , 0, 
               0 , 0 , 0 , 1 , 0 
             ] ); 
    } 

    private function brightness(value:Number):ColorMatrixFilter 
    { 
     return new ColorMatrixFilter( [ 
              1 , 0 , 0 , 0 , value, 
              0 , 1 , 0 , 0 , value, 
              0 , 0 , 1 , 0 , value, 
              0 , 0 , 0 , 1 , 0 
             ] ); 
    } 

    private function contrast(value:Number):ColorMatrixFilter 
    { 
     var a:Number = (value * 0.01 + 1) 
     var b:Number = 0x80 * (1 - a); 
     return new ColorMatrixFilter( [ 
              a , 0 , 0 , 0 , b, 
              0 , a , 0 , 0 , b, 
              0 , 0 , a , 0 , b, 
              0 , 0 , 0 , 1 , 0 
             ]); 
    } 
} 
} 
+0

很酷,謝謝! – Yeti

+0

歡迎:) btw使用您的PB輸出,而不是概述bitmapdata應該工作得更好:) – nicoptere

相關問題