来自文件的Bitmaping [英] Bitmaping from files
问题描述
我想从一个文件创建一个类,其中
1)有参数width和height。
2)以动态分配的二维阵列存储像素数据
3)默认情况下,所有像素颜色均为黑色(红色,绿色和蓝色)
值等于0)。
这是文件
所以我在类图像中修改了我的一些编码,这是我到目前为止所获得的
展开 | 选择 | Wrap | 行号
class图片
{
friend std :: istream& operator>> (std :: istream& input,Image& img);
{
ifstream inFile(" polygons.vec"); //打开文件
if(!inFile)//验证打开
{
cerr<< 错误发生...<< endl;
退出(1);
}
string line = input.img;
}
private:
int width,height;
颜色**像素; //动态分配的二维数组
public:
Image(int X,int Y);
void getpixel();
void setpixel();
void color();
}
我注意到这些项目:
1)为什么朋友的功能在课堂内?
2)为什么文件名是硬编码的?
3)从不在函数中间使用exit()。
你必须a)扔一个异常或b)返回错误代码
表示失败
4)从不在您的班级中放置硬编码的消息。使用错误代码。
如果消息
从任何地方不加弹出,你将永远无法管理你的屏幕布局。
5)a颜色**不是2D数组的地址。它是Color *的地址
,它是单个Color对象的地址。
6)没有构造函数来初始化像素*
7)没有析构函数来清理像素*。
8)C ++没有多维数组。
阅读:
首先,C或C ++中只有一维数组。括号中放置的元素数量:
展开 | 选择 | Wrap | / span> 行号
我用hv语法创建BMP文件将像素数据写入它...
头文件 -
展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号< /跨度>
I want to create a class from a file which
1) has parameters width and height.
2) Stores pixel data in dynamically allocated 2-dimensional array
3)By default all pixel colours are black (red, green and blue
values equal to 0).
This is the file
Expand|Select|Wrap|Line Numbers解决方案so i modified a bit of my coding in the class image and here is what i have got so far
Expand|Select|Wrap|Line Numbers
class Image
{
friend std::istream &operator >> (std::istream &input, Image &img );
{
ifstream inFile("polygons.vec"); // opens the file
if (!inFile) //Verify Open
{
cerr<< "Error Occurs... "<<endl;
exit(1);
}
string line = input.img;
}
private:
int width, height;
Colour **pixel;// dynamically allocated 2D array
public:
Image(int X, int Y);
void getpixel();
void setpixel();
void colour();
}I noticed these items:
1) why is the friend function inside the class??
2) why is the file name hard-coded??
3) never use exit() in the middle of a function.
You have to a) throw an exception or b) return an error code that
indicates failure
4) never put hard-coded messages in your class. Use an error code.
You will never be able to manage your screen layout if messages
pop up unbidden from anywhere.
5) a Colour** is not the address of a 2D array. It is the address
of a Colour* which is the address of a single Colour object.
6) there is no constructor to intialize the pixel*
7) there is no destructor to clean the pixel* up.
8) C++ does not have multi-dimensional arrays.
Read this:
First, there are only one-dimensional arrays in C or C++. The number of elements in put between brackets:
Expand|Select|Wrap|Line Numbers
well I do hv the syntax to create BMP files write pixel data into it.....
The header file-
Expand|Select|Wrap|Line Numbers
这篇关于来自文件的Bitmaping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆