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 6635237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:01:36+00:00 2026-05-25T23:01:36+00:00

I have a Sprite that contains opaque objects surrounded by transparent pixels. I also

  • 0

I have a Sprite that contains opaque objects surrounded by transparent pixels. I also have a Rectangle that represents a part of the Sprite that I want to render using BitmapData.draw().

The problem is that the Rectangle that I obtained also contains transparent parts. How can I narrow the Rectangle to only include the opaque parts and ignore the transparent surroundings?

kapep’s answer is just what I want to do, but the problem is that the source is a Sprite, not a BitmapData object, and I don’t have getColorBoundsRect() on a Sprite.

  • 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-25T23:01:36+00:00Added an answer on May 25, 2026 at 11:01 pm

    You can use getColorBoundsRect for this.

    var mask:uint = 0xFF000000; // ignore rgb, use alpha only
    var transparent = 0x00000000; 
    var rect:Rectangle = imageBitmapData.getColorBoundsRect(mask, transparent, false);
    

    To operate with the pixels of the sprite, it needs to be drawn to a BitmapData first (use BitmapData.draw). Then after getting a smaller rectangle with getColorBoundsRect, create a new BitmapData with the dimensions of that rectangle. The last step is to use copyPixels, to copy the area of the rectangle from first image to the new one.

    var imageBitmapData:BitmapData = new BitmapData(image.width, image.height, true, 0);
    imageBitmapData.draw(image);
    // var rect =  ... as above
    var resultBitmapData:BitmapData = new BitmapData(rect.width, rect.height, true, 0);
    resultBitmapData.copyPixels(imageBitmapData, rect, new Point(0,0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sprite that contains a textfield. Then, I want to create a
I have emoticons in a css sprite image that I want to display within
I have one div classA that contains inside one sprite element of classB. I
I have a sprite that holds a bitmap data. I want to give the
Here is the setup: I have a class called Sprite that contains an image
I have a sprite loaded from a PNG that has an alpha channel. The
I have created a nice joomla website with a sprite navigation that works fine
I'm currently working on the interesting example in cocos2d. I have a sprite, that
I have a logo link that's using a background-image (css sprite). All works fine,
I have a class called Sprite, and ballSprite is an instance of that class.

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.