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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:12:17+00:00 2026-05-24T02:12:17+00:00

In a nutshell I have two images I want to overlay one over the

  • 0

In a nutshell I have two images I want to overlay one over the other using a mask so that only parts of the second image show up. This is part of a real time image processing routine so I need the operation to happen as fast as possible.

Specifically, I have two 32 bit image BGR byte arrays. In addition, I have a byte array that represents an image mask.

I want to generate a new byte array where byte array A is overlayed on top of byte array B using the mask array to decide which byte is used.

What is the quickest way to do this?

I was looking at this wikipedia article about old fashioned sprite masking but I am not sure how to best translate this to C#. http://en.wikipedia.org/wiki/Mask_(computing)

EDIT: I forgot to mention that I can restruct any or all of this to make it run faster.

  • 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-24T02:12:19+00:00Added an answer on May 24, 2026 at 2:12 am

    In principle, masking like this is very simple – assuming the arrays are the same size, this code would do it:

    static void MaskImage(byte[] background, byte[] foreground, byte[] mask)
    {
        for (var i = 0; i < background.Length; ++i)
        {
            background[i] &= mask[i];
            background[i] |= foreground[i];
        }
    }
    

    In a reality this will be quite a bit more complicated – your background is likely to be larger than whatever foreground image you’re masking onto it, and you’ll have to do some arithmetic to place it properly. While tedious to get right, it’s not hard.

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

Sidebar

Related Questions

I have a JAR file that I'm using and I want to modify one
In a nutshell, I have a solution that builds fine in the IDE, and
The below code is from my other questions that I have asked here on
I have some nested tables that I want to hide/show upon a click on
can you have a ruby for loop that has two indexes? ie: for i,j
I have this code copied from C# 4.0 in a nutshell that uses Attribute/Reflection
So the scenario in a nutshell: I have an entity (EF4) that has a
In a nutshell on page1.php I have a calculator that consists of an HTML
I'm using LinqKit (http://www.albahari.com/nutshell/linqkit.aspx) Is there a way to have the following code work
In a nutshell, let's say I have two textboxes, both have RequiredFieldValidator controls. I

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.