Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AWT Image pixel colour problem....help!

843807Feb 15 2002 — edited Mar 1 2002
Hi everyone,

I'm having trouble creating a image object as I would like, it'll probably help if I explain what I'm trying to do...

I'm writing an applet with an 8x8 grid of buttons on representing a picture. Users click on the buttons to change their colour to make an image. (I then encode it to a JPEG so they can observe the difference).

The problem is that I have an integer array of the pixel values on screen (I'm using the system whereby 0 = white, 1 black, 2 red, 3 green and 4 is blue). Now the problem is that I don't know the values the pixels need to be to represent their colour in the image. Can anyone help me out with this?

The code I'm using is below.....

//pixels is my array of pixel values


for(int x = 0; x < pixels.length; x++)
{
//Need to update the pixel values to represent proper colour values
//8 bit RGB
if(pixels[x] == 1)
pixels[x] = 0;
else if(pixels[x] == 2)
pixels[x] = 0;
else if(pixels[x] == 3)
pixels[x] = 0;
else if(pixels[x] == 4)
pixels[x] = 0;
else
pixels[x] = -1;
}

//Create new image from pixel values...
image = createImage(new MemoryImageSource(8, 8, pixels ,0 ,8));

I'm converting the image to a BufferedImage (of type RGB int) after the AWT image is create to encode as a JPEG. Does the BufferedImage being 8bit RGB alter what values I should give the pixels before creating the AWT image?

Hope this all makes sense and you can help me out!

Thanks in advance,

Chris
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2002
Added on Feb 15 2002
3 comments
154 views