Search code examples
javaarrayscountinggrib

How to start a count in java from bottom-left corner?


enter image description hereI know in java the top-left is considered the (0,0) coordinate. I am trying to count the pixel of a file. The file pixel's (0,0) coordinate, starts in the bottom-left corner. The total overall area of the screen is 1121x881. I need to count the pixels in order so that the data matches up with the coordinates. The area I want out of the 1121x881 is 543x451. Can anyone help me do this?


Solution

  • EDIT: It seems like the desired effect is a 543,451 start from the bottom left?

    in that case:

    w= //your desired width
    h= //your desired height
    for(int x=543; x<w+543; x++){
        for(y=(pic.height-451)+h; y<pic.height-h;y++){
           //count;
        }
    }
    

    This code starts at the bottom left, move up 451, over 543, and captures however wide and tall of a section as you specify.


    instead of the standard

    for(int x=0; x<pic.width; x++){
        for(y=0; y<pic.height;y++){
           //count;
        }
    }
    

    why not try

    for(int x=0; x<pic.width; x++){
        for(y=pic.height; y>0;y--){
           //count;
        }
    }
    

    This will start the count from the bottom left hand corner and work upward, then to the left. By changing the limit of the loops, you can define the area you want.

    If you want an area that is 543x451 with the bottom left corner the same as the original image you would do:

    for(int x=0; x<543; x++){
        for(y=pic.height; y>451;y--){
           //count;
        }
    }