编写一个程序以文本文件形式创建64 x 64图像

时间:2019-05-20 21:54:56

标签: java

该程序不使用数组。之所以放在此处,是因为它可用于本节的其他一些程序。

编写一个程序,该程序创建一个64 x 64图像作为文本文件。图像将包含八个越来越高的值的波段。可以将图像视为64行的64整数,但实际上每行写出一个整数。这是为了方便程序输入图像。

图像以8行零开始,因此程序写入8乘64零(作为字符“ 0”)。接下来,图像有8行,每行8个,因此程序将写8乘64的8(作为字符“ 8”)。接下来,图像有8行,每行16条,依此类推。每行写一个值,没有空格或逗号。

使用输出重定向将输出发送到文件。使用此文件作为输入,可以使图像更平滑(上一个练习)或图像显示程序(下一个练习)。

  int sum = 0;
    int col = 0;
    // Compute the smoothed value for non-edge locations in the image.
    for (int row = 1; row < image.length - 1; row++) {
        for (col = 1; col < image[row].length - 1; col++) {
            sum = image[row - 1][col - 1] + image[row - 1][col] + image[row - 1][col + 1] + 
                  image[row][col - 1] + image[row][col] + image[row][col + 1] + 
                  image[row + 1][col - 1] + image[row + 1][col] + image[row + 1][col + 1];
            smooth[row][col] = sum / 9;
        }

    }
    // write out the input
    for (int row = 0; row < image.length; row++) {
        for (int col1 = 0; col1 < image[row].length; col1++) {
            System.out.print(image[row][col1] + " ");
        }
        System.out.println();

//老实说,我不知道该怎么做

0 个答案:

没有答案