超级好用的z字形扫描数组java代码
public static void scanzigzag(int m) { int count = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { System.out.print(block[i][j] + " "); } System.out.println(); } System.out.println( "---------------------------------------------------------------------------------------"); for (int i = 0; i < 2 * n - 1; i++) { int start = i < n ? 0 : (i - n + 1); int end = i < n ? i : (n - 1); if (i % 2 == 0) { for (int j = start; j <= end; j++) { if (count == m) { block[i - j][j] = 0; } else { count++; } System.out.print(block[i - j][j] + " "); } } if (i % 2 == 1) { for (int j = start; j <= end; j++) { if (count == m) { block[j][i - j] = 0; } else { count++; } System.out.print(block[j][i - j] + " "); } } } }
参数m是将到达一定数量的块后,将后面的块设为0,这个方法是我用于DCT变换后解码前选择恢复的块数。
n是数组行数。