Hi, I am new to java programming, but i have this problem:

I open an image, i put ir in array 2 dimensional, teh idea is like this


array[count][0]=x;
array[count][1]=y
array[count][2]=red;
array[count][3]=green;
array[count][4]=blue;
array[count][5]=alpha;


I do so becaude i need to work with colors, but later on i want to save all changes in image. Can you please help me?! Some links with more info could be nice.

Thank you

Hi, I am new to java programming, but i have this problem:

I open an image, i put ir in array 2 dimensional, teh idea is like this


array[count][0]=x;
array[count][1]=y
array[count][2]=red;
array[count][3]=green;
array[count][4]=blue;
array[count][5]=alpha;


I do so becaude i need to work with colors, but later on i want to save all changes in image. Can you please help me?! Some links with more info could be nice.

Thank you

hmmm ... don't have the time to look into it right now, but you're just showing a one-dimensional array.

a two-dimensional one would look like:

String[][] ColorAndDebt = new String[2][2];
ColorAndDebt[0] = {"RED","285"};
ColorAndDebt[1] = {"BLUE","180"};

i think you expect this

Object[][] data = new Object[][] {
                           { 
        	            new ImageIcon("atr.gif"),
                           new ImageIcon("atr.gif")
                             }
                                                  }

hmmm ... don't have the time to look into it right now, but you're just showing a one-dimensional array.

a two-dimensional one would look like:

String[][] ColorAndDebt = new String[2][2];
ColorAndDebt[0] = {"RED","285"};
ColorAndDebt[1] = {"BLUE","180"};

Uhm, no, array[index1][index2] = x is also a two dimensional array, just accessing an individual element rather than an entire array element from the "outer" array.

Anyway, OP. Use BufferedImage to create an image, then use getGraphics to get a Graphics2D object, then use setRGB once for each element.

Edit: But, in any case, unless you simply want to save it in that format to be "human readable", then you should simply be using ImageIO to save it as a regular image (format of your choice, i.e. gif, jpeg, png, etc) and you can use the varying Image methods to retreive the color and coordinate data directly from the image.

Uhm, no, array[index1][index2] = x is also a two dimensional array, just accessing an individual element rather than an entire array element from the "outer" array.

you're right there, but I ment that, since couter was never altered, however still a 2 dimensional array, seemed a lot to be like a 1 dimensional, not a very efficiƫnt way to use a 2 dimensional one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.