【问题标题】:Cs50 pset4 filter grayscale function problemcs50 pset4 filter灰度函数问题
【发布时间】:2022-07-11 04:56:22
【问题描述】:

为什么我们不在 helpers.c 中使用指针?我注意到check50已经通过了,但是如何转换filter.c中的变量“image”呢?

`#include "helpers.h"

// Convert image to grayscale

    void grayscale(int height, int width, RGBTRIPLE image[height][width])
    {
        float tmp;
        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                tmp = (image[i][j].rgbtBlue + image[i][j].rgbtRed + image[i][j].rgbtGreen)/3.0;
                image[i][j].rgbtBlue = (int)(tmp + 0.5);
                image[i][j].rgbtRed = (int)(tmp + 0.5);
                image[i][j].rgbtGreen = (int)(tmp + 0.5);
            }
        }
        return;
    }

`

【问题讨论】:

    标签: function pointers cs50


    【解决方案1】:

    这是因为您在设置image[i][j].rgbtBlue, image[i][j].rgbtGreen, image[i][j].rgbtRed.的值时正在写入文件

    双循环中的以下代码行是做什么的?

    image[i][j].rgbtBlue = (int)(tmp + 0.5);
    image[i][j].rgbtRed = (int)(tmp + 0.5);
    image[i][j].rgbtGreen = (int)(tmp + 0.5);
    

    他们正在逐个像素地更改位图图像文件。该文件位于辅助内存中。它与主存中的变量指针或其地址无关。

    【讨论】:

      猜你喜欢
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2020-07-17
      • 2016-11-28
      相关资源
      最近更新 更多