pic.cpp 854 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "pic.hpp"
  2. //char** picture;
  3. pic::pic(int w, int h) : body(w,h){
  4. picture = new char* [height];
  5. for(int i=0; i<height; ++i)
  6. picture[i] = new char[w];
  7. clear();
  8. }
  9. pic::~pic()
  10. {
  11. delete [] picture;
  12. }
  13. void pic::loadpicture(const char* nome)
  14. {
  15. ifstream input(nome);
  16. char c;
  17. if(!nome){
  18. input.close();
  19. }
  20. else{
  21. for(int i=0; i<height; i++) //rows
  22. for(int j=0; j<width; j++){ //columns
  23. c = input.get(); // get character from file
  24. if(c!='\n') picture[i][j]=c;
  25. if(c=='\n') j--;
  26. }
  27. input.close();
  28. }
  29. }
  30. void pic::clear(){
  31. for(int i=0; i<height; i++)
  32. for(int j=0; j<width; j++)
  33. picture[i][j]=' ';
  34. }
  35. void pic::set_values(int W, int H){
  36. width=W;
  37. height=H;
  38. }
  39. void pic::print(){
  40. for(int i=0; i<height; i++){
  41. for(int j=0; j<width; j++)
  42. cout << picture[i][j];
  43. cout << endl;
  44. }
  45. }