Find edges of an object


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



Copy this code and paste it in your HTML
  1. function findBlingPoints(o:*, n:Number, s:String="right"){
  2. var myBitmapData:BitmapData = new BitmapData(o.width, o.height, true, 0x000000);
  3. myBitmapData.draw(o);
  4. var pixelValue:uint;
  5. var pointArray:Array = [];
  6. var currPixel:Boolean = false;
  7. var lastPixel:Boolean = false;
  8.  
  9. for(var i=0; i<myBitmapData.width; i++){
  10. pixelValue = myBitmapData.getPixel32(i, n);
  11. if(pixelValue==0){currPixel=false}else{currPixel=true};
  12. switch (s){
  13. case "right":
  14. if(!currPixel&&lastPixel){
  15. pointArray[pointArray.length]=i;
  16. pointArray[pointArray.length]=n;
  17. }
  18. break;
  19.  
  20. case "left":
  21. if(!lastPixel&&currPixel){
  22. pointArray[pointArray.length]=i;
  23. pointArray[pointArray.length]=n;
  24. }
  25. break;
  26.  
  27. case "both":
  28. if(lastPixel!=currPixel){
  29. pointArray[pointArray.length]=i;
  30. pointArray[pointArray.length]=n;
  31. }
  32. break;
  33. }
  34. lastPixel = currPixel;
  35. }
  36. return pointArray;
  37. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.