Embedding and using a pixel-bender filter


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package {
  2. import flash.display.Bitmap;
  3. import flash.display.Shader;
  4. import flash.display.Sprite;
  5. import flash.filters.*;
  6. import flash.utils.ByteArray;
  7.  
  8. public class PixelBenderTest extends Sprite
  9. {
  10. [Embed(source='image.jpg')]
  11. private var ImageFile:Class;
  12.  
  13. [Embed(source="filter.pbj" , mimeType="application/octet-stream")]
  14. private var FilterFile : Class;
  15.  
  16. private var shader:Shader;
  17. private var filter:ShaderFilter;
  18. private var bmp:Bitmap;
  19.  
  20. public function PBTest()
  21. {
  22. bmp = new ImageFile() as Bitmap;
  23.  
  24. shader = new Shader( new FilterFile() as ByteArray ) ;
  25. shader.data.size.value = [20];
  26. shader.data.base.value = [400,250];
  27.  
  28. filter = new ShaderFilter(shader);
  29.  
  30. bmp.filters = [ filter ];
  31. addChild(bmp);
  32. }
  33.  
  34. }
  35. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.