error: 8.13802e+06 is outside the range of representable values of type 'unsigned char'
error: 8.13802e+06 is outside the range of representable values of type 'unsigned char'
接近尾声我遇到了一个我无法解决的问题。也许你们中的一个可以:
以下代码的编译工作正常,但是当我启动程序时,我收到此错误消息:
helpers.c:228:42:运行时错误:8.13802e+06 超出了 'unsigned char'
类型的可表示值范围
该代码是一个按块模糊图像的函数,但是第一个像素 [0][0] 没有获得正确的平均值,我不知道为什么我会收到该错误消息。
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
int i;
int j;
int m;
int n;
int averageRed;
int averageBlue;
int averageGreen;
RGBTRIPLE average[height][width];
// For each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel.
for (j = 0; j < width; j++)
//If current height equals 0 AND current width equals 0..
if (i == 0 && j == 0)
{
//..take 2 rows of the picture..
for (m = i; m <= i + 1; m++)
{
//..and take 2 pixels of each row.
for (n = j; n <= j + 1; n++)
{
//Sum up the rgb-values for each of the 2 pixel of the 2 rows.
averageRed = averageRed + image[m][n].rgbtRed;
averageGreen = averageGreen + image[m][n].rgbtGreen;
-> The error line averageBlue = averageBlue + image[m][n].rgbtBlue;
}
}
//Save the average of the values in a separate array after the 2x2 pixel-block
average[i][j].rgbtRed = round((float)averageRed / 4);
average[i][j].rgbtGreen = round((float)averageGreen / 4);
average[i][j].rgbtBlue = round((float)averageBlue / 4);
//Set average-variables to 0
averageRed = 0;
averageGreen = 0;
averageBlue = 0;
}
//From each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel..
for (j = 0; j < width; j++)
{
//...and update the original value with the temporary stored value.
image[i][j].rgbtRed = average[i][j].rgbtRed;
image[i][j].rgbtGreen = average[i][j].rgbtGreen;
image[i][j].rgbtBlue = average[i][j].rgbtBlue;
}
}
}
提前感谢任何提示!
另一个 facepalm-answer :-)..
解决方案非常简单。这只是缺少 averageRed/Green/Blue-variables.
的初始化
没有得到它,因为错误消息仅指向 averageBlue。
再次感谢 M Oehm :-)
接近尾声我遇到了一个我无法解决的问题。也许你们中的一个可以:
以下代码的编译工作正常,但是当我启动程序时,我收到此错误消息:
helpers.c:228:42:运行时错误:8.13802e+06 超出了 'unsigned char'
类型的可表示值范围该代码是一个按块模糊图像的函数,但是第一个像素 [0][0] 没有获得正确的平均值,我不知道为什么我会收到该错误消息。
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
int i;
int j;
int m;
int n;
int averageRed;
int averageBlue;
int averageGreen;
RGBTRIPLE average[height][width];
// For each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel.
for (j = 0; j < width; j++)
//If current height equals 0 AND current width equals 0..
if (i == 0 && j == 0)
{
//..take 2 rows of the picture..
for (m = i; m <= i + 1; m++)
{
//..and take 2 pixels of each row.
for (n = j; n <= j + 1; n++)
{
//Sum up the rgb-values for each of the 2 pixel of the 2 rows.
averageRed = averageRed + image[m][n].rgbtRed;
averageGreen = averageGreen + image[m][n].rgbtGreen;
-> The error line averageBlue = averageBlue + image[m][n].rgbtBlue;
}
}
//Save the average of the values in a separate array after the 2x2 pixel-block
average[i][j].rgbtRed = round((float)averageRed / 4);
average[i][j].rgbtGreen = round((float)averageGreen / 4);
average[i][j].rgbtBlue = round((float)averageBlue / 4);
//Set average-variables to 0
averageRed = 0;
averageGreen = 0;
averageBlue = 0;
}
//From each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel..
for (j = 0; j < width; j++)
{
//...and update the original value with the temporary stored value.
image[i][j].rgbtRed = average[i][j].rgbtRed;
image[i][j].rgbtGreen = average[i][j].rgbtGreen;
image[i][j].rgbtBlue = average[i][j].rgbtBlue;
}
}
}
提前感谢任何提示!
另一个 facepalm-answer :-)..
解决方案非常简单。这只是缺少 averageRed/Green/Blue-variables.
的初始化没有得到它,因为错误消息仅指向 averageBlue。
再次感谢 M Oehm :-)