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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:04:32+00:00 2026-05-22T18:04:32+00:00

I intended to display a 28×28 pixels image inside the window. The pixels have

  • 0

I intended to display a 28×28 pixels image inside the window. The pixels have “0” value, so I expected it to display a window with a black square of 28×28. But no image is displayed instead. Maybe array’s data (I don’t know for sure if pixel values must be an int in range from 0 to 255) must be other in order to display the image. Thanks!

public class ASD {

public static Image getImageFromArray(int[] pixels, int width, int height) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    WritableRaster raster = (WritableRaster) image.getData();
    System.out.println(pixels.length + " " + width + " " + height);
    raster.setPixels(0,0,width,height,pixels);
    return image;
}

public static void main(String[] args) throws IOException {
    JFrame jf = new JFrame();
    JLabel jl = new JLabel();

    int[] arrayimage = new int[784];
    for (int i = 0; i < 28; i++)
    {   for (int j = 0; j < 28; j++)
            arrayimage[i*28+j] = 0;
    }
    ImageIcon ii = new ImageIcon(getImageFromArray(arrayimage,28,28));
    jl.setIcon(ii);
    jf.add(jl);
    jf.pack();
    jf.setVisible(true);
}
  • 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-22T18:04:33+00:00Added an answer on May 22, 2026 at 6:04 pm

    image.getData() returns a copy of the raster.
    Perhaps if you call image.setData(raster) after you modify the raster you will see results.

    Also, setPixels should be given an array large enough to fill all the bands (A, R, G, B) of the raster. I had gotten an array index out of bounds exception until I increased the size of pixels to be 28*28*4.

    For TYPE_INT_RGB, the following should produce a white image:

    public class ASD
    {
      public static Image getImageFromArray(int[] pixels, int width, int height)
      {
        BufferedImage image =
            new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        WritableRaster raster = (WritableRaster) image.getData();
        raster.setPixels(0, 0, width, height, pixels);
        image.setData(raster);
        return image;
      }
    
      public static void main(String[] args) throws IOException
      {
        JFrame jf = new JFrame();
        JLabel jl = new JLabel();
    
        //3 bands in TYPE_INT_RGB
        int NUM_BANDS = 3;
        int[] arrayimage = new int[28 * 28 * NUM_BANDS];
    
        for (int i = 0; i < 28; i++)
        {
          for (int j = 0; j < 28; j++) {
            for (int band = 0; band < NUM_BANDS; band++)
              arrayimage[((i * 28) + j)*NUM_BANDS + band] = 255;
          }
        }
        ImageIcon ii = new ImageIcon(getImageFromArray(arrayimage, 28, 28));
        jl.setIcon(ii);
        jf.add(jl);
        jf.pack();
        jf.setVisible(true);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image which is intended to be a background image, which fills
I intended to create a class which only have static members and static functions.
I have a wrapper generic class that intended to be used with a set
I have some JQuery written which is intended so when a user navigates to
I have to display a list from the database column titled Region .....for every
I have a screen in my windows mobile app that I is intended for
I have this code which is not working jQuery if($(#dis(h3)).length == 0) $(#dis).append(<p>no display</p>);
I'm working on a Titanium app (currently targeted for iPhone deployment, but ultimately intended
Pretty simple code, which I may say worked as intended in Xcode 4.1 but
I have a horizontal menu consisting of <li> elements with display: inline . The

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.