C++ 从同一目录读取图像?
假设在我的C++ 从同一目录读取图像?,c++,image,file,makefile,header-files,C++,Image,File,Makefile,Header Files,假设在我的main.cpp所在的目录中,有一个名为in.png的图像。我必须阅读该图像并将其放入我在主体中创建的b中。我被赋予了一个类PNG,以及读取图像的功能。我也把我的算法发布到下面,我最后一次使用C编程语言3年前,现在我在C++中,我已经忘记了很多。为什么我的算法不起作用,怎么了 巴布亚新几内亚 class PNG { public: PNG(string const & file_name); /** * Copy constructor: creates
main.cpp
所在的目录中,有一个名为in.png
的图像。我必须阅读该图像并将其放入我在主体中创建的b
中。我被赋予了一个类PNG
,以及读取图像的功能。我也把我的算法发布到下面,我最后一次使用C编程语言3年前,现在我在C++中,我已经忘记了很多。为什么我的算法不起作用,怎么了
巴布亚新几内亚
class PNG
{
public:
PNG(string const & file_name);
/**
* Copy constructor: creates a new PNG image that is a copy of
* another.
* @param other PNG to be copied.
*/
};
在png.cpp中,我们有:
PNG::PNG(string const & file_name)
{
_pixels = NULL;
_read_file(file_name);
}
在main.cpp中,这是我的代码
int main
{
PNG a;
PNG*b = NULL;
b = a.PNG(string const & in.png);
if(*b = NULL)
cout << "The image wasn't read" << endl;
return 0;
}
谢谢只需使用:
int main()
{
// Construct a PNG object by passing the name
// of the png file to the constructor.
PNG a("in.png");
return 0;
}
因此,如果我想将该图像写入一个与给定函数相反的文件,我可以执行a.write_out(“output.png”)。。。。这行吗?@user124627,如果类PNG
有这样一个函数,那么是的,它应该。
#include <algorithm>
#include <iostream>
#include "rgbapixel.h"
#include "png.h"
using namespace std;
int main()
{
cout << "me..........." << endl;
PNG a("in.png");
PNG b;
for(size_t i = 0; i < a.width(); i++)
{
for(size_t j = 0; j <a.height(); j++)
{
// *b(i, j) = *a(j, i); erata
// b(i,j) = RGBAPixel * operator()(size_t x, size_t y);
// b(i, j) = operator()(i, j);
//b(i,j) = *operator(i,j);
//b(j,i) = a*operator(i,j);
//b(j,i) = a.operator(i,j);
//b(j, i) = a.*operator(i,j);
}
}
b.writeToFile("output.png");
return 0;
}
[jonathan2@linux-a1 lab_intro]$ make
clang++ -std=c++1y -stdlib=libc++ -c -g -O0 -Wall -Wextra -pedantic main.cpp
main.cpp:24:29: error: expected ')'
b(i,j) = *operator(i,j);
^
main.cpp:24:28: note: to match this '('
b(i,j) = *operator(i,j);
^
main.cpp:24:20: error: use of undeclared 'operator()'
b(i,j) = *operator(i,j);
^
2 errors generated.
make: *** [main.o] Error 1
int main()
{
// Construct a PNG object by passing the name
// of the png file to the constructor.
PNG a("in.png");
return 0;
}