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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:03:13+00:00 2026-06-05T04:03:13+00:00

I have some really simple code that’s just not working: int[] manualPixels = new

  • 0

I have some really simple code that’s just not working:

int[] manualPixels = new int[width * height * 3];
for (int index = 0; index < manualPixels.length; index++) {
    if (index % 3 == 2) {
        manualPixels[index] = 255;
    }
}
BufferedImage pixelImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);    
pixelImage.setRGB(0, 0, width, height, manualPixels, 0, width);

ImageIO.write(pixelImage, "jpeg", tempFile);

This should, as far as I can determine, output a red, green, or blue image, depending upon whether 0, 1, or 2 is used in the if statement in the for loop. The problem is that instead of that, I invariably get blue and black stripes, no matter which pixels I set. For instance:

enter image description here

I’m sure there must be some basic thing that I’m doing wrong here, I’m just not seeing what it is. Any ideas?

  • 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-05T04:03:14+00:00Added an answer on June 5, 2026 at 4:03 am

    INT_RGB packs all the channels into the least significant three octets of an int. This means that you are setting every third pixel to blue, and the rest are left black. (This however doesn’t match with your image – did you change the code after generating it?)

    Try this instead:

    int[] manualPixels = new int[width * height];
    for (int index = 0; index < manualPixels.length; index++) {
        switch (index % 3) {
            case 0: manualPixels[index] = 0xFF0000; break; // red
            case 1: manualPixels[index] = 0x00FF00; break; // green
            case 2: manualPixels[index] = 0x0000FF; break; // blue
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been working on some code streamlining and have realised that it would be really
I have some Clojure code that seems maddeningly simple and yet is throwing an
This makes no sense. I have some code that has a simple LinearLayout and
I am writing some simple code that tries to deduce whether or not a
I have some really funky code. As you can see from the code below
I have some really nice Python code to do what I need to do.
I have some confusion. Not really a bug or issue I am facing. I
Right now I have some functionality working but its really ugly and I know
I have some ideas, some that I have accumulated over time, but I really
I have a really long string, I just want to extract some certain string

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.