tags:

views:

45

answers:

3

hey i have using j2me to read an image

i want to do some process on that image like Darkenes , lightens

i already read image as an input stream

        InputStream iStrm = getClass().getResourceAsStream("/earth.PNG");
         ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

       int ch;

  while ((ch = iStrm.read()) != -1){
    bStrm.write(ch);


    byte imageData[] = bStrm.toByteArray();
   Image im = Image.createImage(imageData, 0, imageData.length);

how can i get RGB values or how can i add some values to the array of pixles
imageData[] so it can more lightens or darkness ,

is there header data including in the input stream i had read , that cause me error when iam adding some values to it ?

+1  A: 

I think you should be able to do the following:

int width = im.getWidth();
int height = im.getHeight();
int[] rgbData = new int[width*height]; // since we are working with rgba

im.getRGB(rgbData, 0, width, 0, 0, width, height);

// now, the data is stored in each integer as 0xAARRGGBB, 
// so high-order bits are alpha channel for each integer

Now, if you want to put them into three arrays, one for each channel, you could do the following:

int red[][] = new int[width][height];
int green[][] = new int[width][height];
int blue[][] = new int[width][height];

for (int i = 0; i < width; i++)
{
  for (int j = 0; j < height; j++)
  {
    red[i][j] = rgb[i*width + j] & 0xFF0000;
    green[i][j] = rgb[i*width + j] & 0xFF00;
    blue[i][j] = rgb[i+width + j] & 0xFF;
  }
}
jwir3
this is incorrect, why you are multiply the array by 4. Every pixel in the image is an integer which can hold the ARGB data. the array should be in width*height size only.
Mahdi Hijazi
Yep, you're right. I edited the post to reflect this.
jwir3
A: 

thanks alot

but can you help me how to sepearte each channel in array

i have problems how to read argb and with shift

Color class is not part of JME, it is part of JSE
Mahdi Hijazi
Added this to my original answer.
jwir3
A: 

i have try it

but i have some problems with values of red , green and blue

it is more than 255 such than 65280

and how i can i redraw iamge using red and green and blue

after i add some values to them ;