Sorry, that code is still wrong.
Main Topics
Browse All TopicsI want to create a chess board image with size which is the same as another image (size w*h). The tile size of each small square is 8*8. I intend to use 4 for loop to create this chess board, the first two for loop is to divide the board to small numbers of square. And the next two loop is to assign the value to each pixel in this small square. Code is bellow.
w and h are width and height of the checker board I want to create.
numw and numh is the number of small squares by each size we can count.
I have several questions:
1. Do you have any comment about the code? Is it work as I want?
2. I want to convert this matrix to an image so I can manipulate it with other gray scale image but I have problem because here the matrix is an array which has 2 dimensions [x][y], but what I need is a image like an array(x,y). How can I avoid using matrix here and use array instead, so I can get the image like a chess board.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I think the problem is in "if" condition:
if ((i+j)%2 ==0)
checkerboard.putPixel(k, l, 255); //white value;
else
checkerboard.putPixel(k, l, 0); //black value;
}
}
Because i and j here is not the number of column and row, so when it increase by tilesize which is 12, the next value is also 24, and the modulo return white value, which is correct.
I'm thinking about add numw and numh to this code but don't know where to put it in, maybe we need another for loop.
Business Accounts
Answer for Membership
by: InteractiveMindPosted on 2009-09-15 at 04:55:58ID: 25333864
I don't think your second pair of for-loops are right.
Also, if the matrixchessboard elements represent the colour, then white should be 0xffffff, not 255.
You can also shorten the code slightly by placing the if-statement inside the for-loops.
Moreover, I'm not sure why you've hard-coded 8 and 12 in the nested for-loops.
Regarding point 2), what is the difference between an array and a matrix?
Select allOpen in new window