Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 735347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:28:44+00:00 2026-05-14T07:28:44+00:00

Let say I have a BitmapData with different pixels representing an object, and some

  • 0

Let say I have a BitmapData with different pixels representing an object, and some black pixels around it that I want to remove.

I would like to obtain a new BitmapData, with width and height of the object represented by non-black pixels.

For example, let say I have a BitmapData 400x400px, but the object represented by non-black pixels occupies the rect: x=100, y=100, width=200, height=200. I want to get new BitmapData representing that rect, all black pixels should be removed. Of course, i have no coordinates for that rectangle, i need somehow to make difference between a full black bitmapdata and the original one, and construct a new bitmapdata (different width and height).

Any idea on how to do this please ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:28:44+00:00Added an answer on May 14, 2026 at 7:28 am

    You can use getColorBoundsRect to find the dimensions of the differently-colored-pixels inside your BitmapData:

    //some fake data
    var yourBigBmd:BitmapData = new BitmapData( 300, 300, false, 0 );
    yourBigBmd.fillRect( new Rectangle( 10, 10, 30, 60 ), 0xFF0000 );
    //a little notch
    yourBigBmd.fillRect( new Rectangle( 10, 10, 10, 10), 0x00000 );
    
    var blackColor:uint = 0x000000;
    var littleBmdBounds:Rectangle = yourBigBmd.getColorBoundsRect( 0xFFFFFF, blackColor, false );
    trace( "littleBmdBounds: " + littleBmdBounds );
    

    This will trace littleBmdBounds: (x=10, y=10, w=30, h=60)

    Next, we need to copy what’s in those bounds into a new BitmapData:

    var littleBmd:BitmapData = new BitmapData( littleBmdBounds.width, littleBmdBounds.height, true, 0 );
    var mx:Matrix = new Matrix();
    mx.translate( -littleBmdBounds.x, -littleBmdBounds.y );
    littleBmd.draw( yourBigBmd, mx );
    

    Finally, use threshold to remove any remaining black and make it transparent:

    var blackAlphaColor:uint = 0xFF000000;
    var transparentColor:uint = 0x00000000;
    littleBmd.threshold( littleBmd, littleBmd.rect, littleBmd.rect.topLeft, "==", blackAlphaColor, transparentColor )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have a file that contains a serialized object by BinaryFomatter. Now
let say i have a page , and i want to allow 3rd party
Let say i have some words AB, AAB, AA. AB is not a prefix
Let say i have a field 'category' with the value '1|2|3'. I want to
Let say I have a request table, that looks as follows: RequestId INT ReferenceNumber
Let say I have a Transformation class that extending a CommonDomain class. and I
Let say I have a project that contains a packages.config file. Now when I
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let say you have any console application that is easily to start, later when
Let say I have a page with 100 objects and each page is around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.