This site requires JavaScript, please enable it in your browser!
Greenfoot back
TheGoldenProof
TheGoldenProof wrote ...

2018/9/13

Is this a correct way of turning pixels into an array

TheGoldenProof TheGoldenProof

2018/9/13

#
for (int y = 0; y < getHeight(); y++) {
    for (int x = 0; x < getWidth(); x++) {
        int index = x*y + x;
        Color c = getColorAt(x, y);
        pixO[index] = c;
    }
}
This is my code that I'm using on a 800x800 image, but there's one problem. Pixel 809's color is null. Its location should be (1,8) and I looked at that pixel and it looks normal and blueish so it HAS a color. Any reason why this isn't working? also would these be the correct ways to turn the index back into x and y?
int x = index % getWidth();
int y = index / getWidth();
EDIT: I printed the pixel at (1,8) to the console so there's nothing wrong with that pixel. EDIT 2: I realized I did my pixel thing completely wrong. Its getWidth() * y + x. still, using that, my pixel should be (1,8) but pixel 809 and pixel (1,8) have different values, so something isn't right still. EDIT 3: Idk why I missed this but i had my x's and y's swapped in my point. pixel 809 is at (9,1). jeez me. Anyway, I still want to know if my way of converting back looks good.
danpost danpost

2018/9/14

#
TheGoldenProof wrote...
I still want to know if my way of converting back looks good.
Looks good to me.
TheGoldenProof TheGoldenProof

2018/9/14

#
cool thanks
You need to login to post a reply.