Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / December 2008



Tip: Looking for answers? Try searching our database.

find bounds of contiguous transparent pixels

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rritchey - 29 Sep 2008 19:28 GMT
I have the need to find the largest rectangle of ONLY transparent pixels in a
transparent PNG.  The transparent region is non-rectangular, so
getColorBoundsRect returns a rectangle that also contains non-transparent
pixels.  Is there a way I can check for a rectangle that contains only the
color I set?
rritchey - 30 Sep 2008 16:09 GMT
Barring finding a method to do this, I hacked together a solution.

First, I found the bounds of all transparent pixels using getColorBoundsRect.

Next I iterated from the top-down until I found the first line with only
transparent pixels to revise the top edge

Finally I iterated from the bottom-up until finding the bottom line of only
transparent pixels to revise the bottom edge.

I was able to compensate like as such because I know that the rectangle is not
impeded from the sides at any point, otherwise I would have had to find the
left and right edges as well.

I feel like there should be an easier way (and also a less processor-intensive
way) to do this.

var clBD:BitmapData = new BitmapData(735,600,true, 0x00FFFFFF);
    clBD.draw(contentLoader.content);
    var transparentRect:Rectangle =
clBD.getColorBoundsRect(0xFF000000,0x00000000,true);
   
    var top:Number = transparentRect.y;
    var bottom:Number = transparentRect.y + transparentRect.height;
   
    for(var i:uint = transparentRect.y ; i < bottom ; i++){
        for(var j:uint = transparentRect.x ; j < (transparentRect.x +
transparentRect.width - 1) ; j++){
            if((clBD.getPixel32(j,i) >> 24 & 0xFF) > 50){
                top++;
                j = transparentRect.x + transparentRect.width;
            }else if(j == (transparentRect.x + transparentRect.width - 2)){
                i = bottom;
                j = transparentRect.x + transparentRect.width;
            }
        }
    }
   
    for( i = (transparentRect.y + transparentRect.height) ; i > top ; i -- ){
       
        for( j = transparentRect.x ; j < (transparentRect.x + transparentRect.width
- 1) ; j++){
            if((clBD.getPixel32(j,i) >> 24 & 0xFF) > 10){
                bottom -- ;
                j = transparentRect.x + transparentRect.width;
            }else if(j == (transparentRect.x + transparentRect.width - 2)){
                i = top;
                j = transparentRect.x + transparentRect.width;
            }
        }
       
    }
   
    clBD.dispose();
rritchey - 09 Dec 2008 18:21 GMT
Wow, 3 months and no-one can find a better way to do this?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.