java - Get specific pixel from 1D pixel array -


I have a pixel array that has many colors.

  int w = 32; Int h = 32; Int [] pixel = new int [w * h];  

As you can see, the image of this example has 32x32 dimensions, all the pixels are stored in one-dimensional array.

For example, I want to pick pixels from coordinate (5/0), that means the fifth element in the first line of the image. The problem now is that I have got one dimensional pixel array Otherwise, just call me

  int target = pixels [5] [0];  

How can I get this specific pixel from a one dimensional array?

like this:

  public int getPixel (x, y ) {// W is your width (number of pixels in line) == 32 return pixels (x + w * y); }  

It assumes that the pixel data is stored in the order-line-line, so you "leave" in the right row (which is "height" x (row per pixel Number)) and then add column


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -