BufferedImage & pixels.

A

aaaaaaaaaaaa

Hello

How to create "black&white" image?


First BufferedImage:

BufferedImage bImage = new BufferedImage(imageWidth,
imageHeight,BufferedImage.TYPE_BYTE_GRAY);



And then my code is:

for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++) {
int pix = 0xff;
pix = (pix << 8) | Y[x][y];
pix = (pix << 8) | Y[x][y];
pix = (pix << 8) | Y[x][y];
bImage.setRGB(x, y, pix);
}


or:


int i = 0;
int[] tabColor = new int[256];
for (i = 0; i < 256; i++)
tabColor = (new Color(i, i, i)).getRGB();

for (int x = 0; x < imageWidth; x++)
for (int y = 0; y < imageHeight; y++)
bImage.setRGB(x, y, tabColor[Y[x][y]]);



Y[x][y] - integer values from 0 to 255.

Both metods does the same effect. Bad effect.
They create b&w image, but with terrible contrast - image is very dark.

What's wrong?


My only idea is stretching histogram to improve contrast :)
 
C

Chris Smith

aaaaaaaaaaaa said:
Y[x][y] - integer values from 0 to 255.

Both metods does the same effect. Bad effect.
They create b&w image, but with terrible contrast - image is very dark.

What's wrong?

My guess is that your "Y" array contains an image with bad contrast.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

aaaaaaaaaaaa

My guess is that your "Y" array contains an image with bad
contrast.

Try again :)
Below code makes ".raw" file, which looks great...


byte[] r = new byte[imageWidth * imageHeight];
int k = 0;

for (int i = 0; i < imageHeight; i++)
for (int j = 0; j < imageWidth; j++) {
r[k] = (byte) Y[j];
k++;
}

try {
out.write(r);
} catch (IOException e) {
e.printStackTrace();
}



Any other ideas, how to create b&w BufferedImage?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top