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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:54:50+00:00 2026-06-17T17:54:50+00:00

I am working on an image collision mechanism that uses long values as bitmasks

  • 0

I am working on an image collision mechanism that uses long values as bitmasks for each image and sets each bit to 1 if the pixel is not excluded (transparent in most cases), 0 otherwise. I wrote a test method to write the bitmasks to a text file as 1s and 0s. It seems to me that, in theory, because the image is read row by row, the 1s and 0s should resemble the image itself.

That isn’t really what I got. Is the problem with my bit-assigning code or my printing code? Or is it supposed to look like that?

Image Parsing

    int[] data = ColorUtils.getImageData(img);
    bounds = new Rectangle(img.getWidth(), img.getHeight());
    int wt = (int) bounds.getWidth();
    int ht = (int) bounds.getHeight();
    bitmasks = new long[ht];
    for(int y = 0; y < ht; y++) {
        long bitmask = 0;
        for(int x = 0; x < wt; x++) {
            if(data[x + y * wt] != excludedColor)
                bitmask = (bitmask << 1) + 1;
            else
                bitmask = bitmask << 1;
        }
        bitmasks[y] = bitmask;
    }

File Printing

    PrintWriter pw =  null;
    try {
        pw = new PrintWriter(new File("/home/brian/Desktop/imageModel.txt"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }
    for(int y = 0; y < bounds.getHeight(); y++) {
        long bitmask = bitmasks[y];
        for(int x = 0; x < bounds.getWidth(); x++) {
            pw.print(String.valueOf((bitmask >> (x + y * (int) bounds.getWidth())) & 1));
        }
        pw.println();
        pw.println();
    }
    pw.close();

Image:

Test image being parsed

Text file produced: View

  • 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-17T17:54:51+00:00Added an answer on June 17, 2026 at 5:54 pm

    Your image parsing looks mostly fine to me, supposing you can actually store an entire row into a long without overflowing it (and also supposing you are going through the data by considering all the channels correctly, which to me is wrong in your code). But on the “File Printing” I don’t see how it could be correct. You are storing one bitmask per row, so if we could index it, bitmask[width - 1] would represent the first column in a given row, bitmask[width - 2] the second column, …, and bitmask[0] would represent the last column in that row. So two things need to be corrected in the unpacking phase: 1) loop from x = width – 1 down to 0; 2) then unpack it by doing ((mask >> x) & 1).

    After resizing your image to 50×50 and considering that a alpha value <= 2 represents the background, here is what I obtain:

    00000000000000000111111111111111000000000000000000
    00000000000000011111111111111111110000000000000000
    00000000000001111111111111111111111100000000000000
    00000000000011111111111111111111111111000000000000
    00000000001111111111111111111111111111100000000000
    00000000011111111111111111111111111111110000000000
    00000000111111111111111111111111111111111000000000
    00000001111111111111111111111111111111111100000000
    00000011111111111111111111111111111111111110000000
    00000011111111111111111111111111111111111111000000
    00000111111111111111111111111111111111111111000000
    00001111111111111111111111111111111111111111100000
    00001111111111111111111111111111111111111111100000
    00011111111111111111111111111111111111111111110000
    00011111111111111111111111111111111111111111110000
    00111111111111111111111111111111111111111111111000
    00111111111111111111111111111111111111111111111000
    00111111111111111111111111111111111111111111111000
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    01111111111111111111111111111111111111111111111100
    00111111111111111111111111111111111111111111111100
    00111111111111111111111111111111111111111111111000
    00111111111111111111111111111111111111111111111000
    00011111111111111111111111111111111111111111111000
    00011111111111111111111111111111111111111111110000
    00011111111111111111111111111111111111111111110000
    00001111111111111111111111111111111111111111100000
    00000111111111111111111111111111111111111111100000
    00000111111111111111111111111111111111111111000000
    00000011111111111111111111111111111111111110000000
    00000001111111111111111111111111111111111100000000
    00000001111111111111111111111111111111111100000000
    00000000111111111111111111111111111111111000000000
    00000000011111111111111111111111111111110000000000
    00000000000111111111111111111111111111000000000000
    00000000000011111111111111111111111110000000000000
    00000000000000111111111111111111111000000000000000
    00000000000000001111111111111111100000000000000000
    00000000000000000011111111111110000000000000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with AVCaptureSession for capturing the image. Its working fine but not giving
I am not getting my image working. Can anyone tell me what I am
UPDATE: I found this enormously helpful article explaining canvas per-pixel collision detection. I'm working
i'm working on image processing, and i'm writing a parallel algorithm that iterates over
I am working with an image uploader. The issue is that the image uploader
I am trying to find a working jQuery image preloader that plays well with
I have a working jquery image carousel that I was building. It's mostly finished
I have a simple function that inserts an animated working image, and then display
I am working on image processing library in c#. want to improve performance/speed and
I'm working on an image-processing software on iPhone and get stuck in the selective

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.