This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

single dimension array to multi dimension

 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the requirement in the project to store the single dimensional array value to multi dimensioinal array.
e.g.
I ve array of blocks(area)from which I want to split each block(area) into X,Y-co-ordinates and store it in 2 dimensional array.
int[i][j]=pix[i][];something like that.
So how can I achieve it.right now I m getting INCOMPATIBLE TYPE error.please it is urgent.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your code so we can see what you are trying to do.
Also, I am going to move this to Java General as it doesn't specifically relate to the exam.
Bill
 
Greg Up
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not positive about the contents of your first array...
This would be much easier for us if you could post your code as mentioned above.
Pressing onward, the most predictable way to assign the contents of one array to a second array is simply setting up loops and making the assignments inside.
In the case of a two dimensional array, you would normally set up nested loops.
HTH,
-Greg
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code.
I wish to grab the pixels of an image(1 dimension)and save it in an array converting the image inot x,y coordinates and rotate that coordinates accordingly to rotate the image ultimately.
--------------------code------------------------------
import java.applet.*;
import java.awt.image.*;
import java.util.*;
public class rotate extends Applet
{
Dimension d;
Image img;
int r=1,j;
int x,y;
int w,h;
int pixels[][],pix[][];
public void init()
{
setBackground(Color.white);
d = getSize();
w = d.width;
h = d.height;
try
{
img = getImage(getDocumentBase(),getParameter("img"));


w = img.getWidth(null);
h = img.getHeight(null);

pixels = new int[w*h][];
pix = new int[w*h][];
PixelGrabber pg = new PixelGrabber(img,0,0,w,h,pixels,0,w);

pg.grabPixels();

}
catch(InterruptedException e)
{ };

for(int i=0;i<h;i++)>
{

for(j=0;j<w;j++)>
{
int p[i][j] =pixels[i][];
x=(int)i*Math.cos(3.14*90/180);
y=(int)j*Math.sin(3.14*90/180);
pix[x][y]=p[i][j];


}
img = createImage(new MemoryImageSource(w,h,pix,0,w));

}
public void update()
{}
public void paint(Graphics g)
{
g.drawImage(img,0,0,this);

}

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic