假设rgbapixel是rgbapixel.h文件中的一类像素,所以它具有绿色,蓝色,红色等公共成员的颜色。 PNG是png.h文件中的一类图像,因此它具有图像宽度和高度作为私有成员,然后它有两个公共函数返回宽度和高度。我应该如何纠正这个指针问题,它给我一个错误
在我的main.cpp中,这里是代码;
// sets up the output image
PNG * setupOutput(int w, int h)
{
PNG * image = new PNG(w, h);
return image;
}
void sketchify()
{
// Load in.png
PNG * original = new PNG;
original->readFromFile("in.png");
int width = original->width();
int height = original->height();
// Create out.png
// PNG * output; // i change this
PNG * output = new PNG;
setupOutput(width, height);
// Loud our favorite color to color the outline
RGBAPixel * myPixel = myFavoriteColor(192);
// Go over the whole image, and if a pixel differs from that to its upper
// left, color it my favorite color in the output
for (int y = 1; y < height; y++)
{
for (int x = 1; x < width; x++)
{
// Calculate the pixel difference
RGBAPixel * prev = (*original)(x-1, y-1); // previous top lfet
RGBAPixel * curr = (*original)(x , y ); // current
// subtracting to see diffrence between pixels
int diff = abs(curr->red - prev->red ) +
abs(curr->green - prev->green) +
abs(curr->blue - prev->blue);
// If the pixel is an edge pixel,
// color the output pixel with my favorite color
RGBAPixel * currOutPixel = (*output)(x,y);
if (diff > 100)
currOutPixel = myPixel; // something wrong
}
}
// Save the output file
output->writeToFile("out.png");
// Clean up memory
delete myPixel;
delete output;
delete original;
当我执行代码时,出现类似错误;
[EasyPNG]: Warning: attempted to access non-existent pixel (407, 306);
Truncating request to fit in the range [0,0] x [0,0].
[EasyPNG]: Warning: attempted to access non-existent pixel (408, 306);
Truncating request to fit in the range [0,0] x [0,0].
我在哪里写的“什么是错的”,我已被告知,这里面就有一个错误。我没看到它。 'mypixel'和currout,两者都成功地作为指针声明,所以我不明白这个声明怎么会是错误的。如果我试图改变它,我会遇到编译错误。帮助
我没有看到任何设置输出大小的地方。 – user3344003 2014-09-05 01:10:34
我没有看到任何输出“EasyPNG”的地方,这意味着这是_not_你的[testcase](http://sscce.org)。 – 2014-09-05 02:19:55