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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:31:01+00:00 2026-05-27T12:31:01+00:00

I programmed something like paint. I have JPanel and I can draw on it.I’m

  • 0

I programmed something like paint. I have JPanel and I can draw on it.I’m using only black line. I wanna convert it to binary array, where 1 is when pixel is black, 0 when is white (background). It’s possible? How to do this?

  • 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-27T12:31:02+00:00Added an answer on May 27, 2026 at 12:31 pm

    In a nutshell, create a BufferedImage with the same dimensions as your JPanel and paint the panel to the image. Then you can iterate over the image raster to get the sequence of pixel color values corresponding to black and white. For example

    // Paint the JPanel to a BufferedImage.
    Dimension size = jpanel.getSize();
    int imageType = BufferedImage.TYPE_INT_ARGB;
    BufferedImage image = BufferedImage(size.width, size.height, imageType);
    Graphics2D g2d = image.createGraphics();
    jpanel.paint(g2);
    
    // Now iterate the image in row-major order to test its pixel colors.
    for (int y=0; y<size.height; y++) {
      for (int x=0; ix<size.width; x++) {
        int pixel = image.getRGB(x, y);
        if (pixel == 0xFF000000) {
          // Black (assuming no transparency).
        } else if (pixel == 0xFFFFFFFF) {
          // White (assuming no transparency).
        } else {
          // Some other color...
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have a perl program that I can call with something like:
Q1: Is there something like too much ajax?? Explanation: I have been seeing programmers
I think I have something like programmer's OCD. I like my code to be
I programmed a bluetooth Television-Remote control for cellphones in J2ME using javax.microedition.lcdui.* (Gauge, List,
Let's say I have some code like the following, and that processData gets executed
There is something that I cannot understand in C#. You can cast an out-of-range
I'm looking for a perfect text editor :) The must have list: vim-like modal
There is series of functions like print_int, print_endline and Printf in OCaml. I can't
I have been using two libraries, SFML and Box2D, while at the same time
I just re-read The Pragmatic Programmer (my third time reading it...I get something new

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.