tell me the best way to copy images by using the pixel array?

The code you have uses scanline=8 as last parameter to setRGB and also wrong logic in copyNTimes which causes your stripped effect. If you want 8×8 pixel image repeating into 64×64 pixel image as 8×8 blocks either replace your setRGB call with this to repeat the small image into the larger one:

for (int x = 0 ; x < 64 ; x += 8)
    for (int y = 0 ; y < 64 ; y += 8)
        copiedNTimes.setRGB(x, y, 8, 8, smallPixels, 0, 8);

Or replace your setRGB call with this to build the larger int[] first and apply it in one step:

copiedNTimes.setRGB(0, 0, 64, 64, copied, 0, 64);

static int[] copyNTimes(int[] small, int[] big){
    for(int x = 0 ; x < big.length; x++){
        big[x] = small[8 * ((x / 64) % 8) + (x % 8)];
    }
    return big;
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top