12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "pic.hpp"
- //char** picture;
- pic::pic(int w, int h) : body(w,h){
- picture = new char* [height];
- for(int i=0; i<height; ++i)
- picture[i] = new char[w];
- clear();
- }
- pic::~pic()
- {
- delete [] picture;
- }
- void pic::loadpicture(const char* nome)
- {
- ifstream input(nome);
- char c;
- if(!nome){
- input.close();
- }
- else{
- for(int i=0; i<height; i++) //rows
- for(int j=0; j<width; j++){ //columns
- c = input.get(); // get character from file
- if(c!='\n') picture[i][j]=c;
- if(c=='\n') j--;
- }
-
- input.close();
- }
-
- }
- void pic::clear(){
- for(int i=0; i<height; i++)
- for(int j=0; j<width; j++)
- picture[i][j]=' ';
- }
- void pic::set_values(int W, int H){
- width=W;
- height=H;
- }
- void pic::print(){
- for(int i=0; i<height; i++){
- for(int j=0; j<width; j++)
- cout << picture[i][j];
- cout << endl;
- }
- }
|