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

  • SEARCH
  • Home
  • 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 8806525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:08:53+00:00 2026-06-14T02:08:53+00:00

I need to draw on a bitmap but not draw on the transparent pixels

  • 0

I need to draw on a bitmap but not draw on the transparent pixels of it?

Example picture here: https://i.stack.imgur.com/QvJTZ.png

I have written this code :

import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Matrix;

var s:S = new S();
var m_bitmapData = new BitmapData(s.width, s.height, true, 0x00000000);
m_bitmapData.draw(s);
var hole=new Sprite();

var hole_matrix:Matrix
hole.graphics.beginFill(0x000000);
hole.graphics.drawCircle(0,0,30);


var bmp:Bitmap = new Bitmap(m_bitmapData);
bmp.x = 50
bmp.y =50 

stage.addChild(bmp);

addEventListener(Event.ENTER_FRAME,asd);
function asd(e:Event):void{
    hole_matrix=new Matrix();
    hole_matrix.translate(mouseX-bmp.x,mouseY-bmp.y);
    m_bitmapData.draw(hole,hole_matrix);
}

But result is such as picture “NO”.

Can someone please explain ?

  • 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-06-14T02:08:55+00:00Added an answer on June 14, 2026 at 2:08 am

    Preserve alpha channel, then copy it back.

    var tempBD:BitmapData=new BitmapData(m_bitmapData.width,m_bitmapData.height,true,0);
    ...
    function asd(e:Event):void {
        ...
        tempBD.copyChannel(m_bitmapData,m_bitmapData.rect,new Point(),BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
        m_bitmapData.draw(hole,hole_matrix);
        m_bitmapData.copyChannel(tempBD,tempBD.rect,new Point(),BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
    }
    

    Basically what you do: You have a BitmapData elsewhere that has the same size as your canvas BitmapData, then you copy alpha channel into that BitmapData, draw what you want, then copy alpha channel back. Whatever was transparent, remained transparent. Note, if you never want the alpha channel to change, you can copyChannel() it away only once, and then just restore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to draw/print a text, but i need a transparent background. I
I am attempting to draw a bitmap along a rectangle, but I am not
I need to draw a circle onto a bitmap in a specific colour given
In my app I need to draw a widget contents onto Bitmap. The code(pseudo)
A need to draw an X in a View using Shapes , but the
I need to crop a Bitmap, but instead of having a rectangular cropped image
this thread is almost what I need: Creating a GraphicsPath from a semi-transparent bitmap
I need to draw a rectange,circle and line and then animate them(press left ->
I need to draw vertical and horizontal rectangle / bands (like in Gantt charts)
I need to draw simple alpha maps in xna which depends on current game

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.