Advertisement
Guest User

Untitled

a guest
May 5th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1.  
  2. public class RGBImage {
  3. private int columns;
  4. private int rows;
  5. private RGBColor[][]pic;
  6.  
  7.  
  8. public RGBImage(int rows, int cols){
  9.  
  10. this.columns=cols;
  11. this.rows=rows;
  12. pic=new RGBColor[cols][rows];
  13. for (int i = 0; i < cols; i++) {
  14. for (int j = 0; j < rows; j++) {
  15. pic[i][j]=new RGBColor();
  16.  
  17.  
  18. }
  19. }
  20.  
  21.  
  22. }
  23. public RGBImage(RGBColor[][]pixels){
  24. pic=new RGBColor[pixels.length][pixels[0].length];
  25. for (int i = 0; i < pixels.length; i++) {
  26. for (int j = 0; j < pixels[0].length; j++) {
  27. pic[i][j]= new RGBColor (pixels[i][j]);
  28.  
  29.  
  30. }
  31. }
  32. }
  33.  
  34. public RGBImage(RGBImage other){
  35.  
  36. int cols=other.getPic().length;
  37. int rows=other.getPic()[0].length;
  38. pic=new RGBColor[cols][rows];
  39. for (int i = 0; i < cols; i++) {
  40. for (int j = 0; j < rows; j++) {
  41. pic[i][j]=other.getPic()[i][j];
  42. }
  43. }
  44. }
  45.  
  46. public int getWidth() {
  47. return columns;
  48. }
  49. public void setcolumns(int columns) {
  50. this.columns = columns;
  51. }
  52. public int getHeight() {
  53. return rows;
  54. }
  55. public void setRows(int rows) {
  56. this.rows = rows;
  57. }
  58. public RGBColor[][] getPic() {
  59. return this.pic;
  60. }
  61. public void setPic(RGBColor[][] pic) {
  62. this.pic = pic;
  63. }
  64. /*public void toStrin(){
  65. for (int i = 0; i < columns; i++) {
  66. for (int j = 0; j < rows; j++) {
  67. System.out.println(pic[i][j].getBlue()+", "+pic[i][j].getGreen()+", "+pic[i][j].getRed());
  68. }
  69. }
  70. }
  71. */
  72.  
  73. public RGBColor getPixel (int rows, int cols){
  74. if (this.rows>=rows||this.columns>=cols)
  75. return this.pic[rows][cols];
  76. else
  77. return new RGBColor();
  78. }
  79.  
  80.  
  81. public void setPixel (int row, int col, RGBColor pixel){
  82. this.pic[row][col]= new RGBColor (pixel);
  83. }
  84.  
  85. public boolean equales (RGBImage other){
  86. if (this.columns==other.columns&&this.rows==other.rows&&ifif(other.getPic())){
  87. return true;
  88. }
  89. return false;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. private boolean ifif (RGBColor[][] other){
  96. for (int i = 0; i < other.length; i++) {
  97. for (int j = 0; j < other[0].length; j++) {
  98. if (!this.pic[i][j].equals(other[i][j]))
  99. return false;
  100.  
  101.  
  102. }
  103. }
  104. return true;
  105. }
  106.  
  107.  
  108.  
  109. public void flipHorizontal (){
  110. RGBColor[][] EZER = new RGBColor[this.columns][this.rows];
  111.  
  112. for (int i = 0; i<this.columns; i++){
  113. for (int j=0; j<this.rows; j++){
  114. EZER[i][j]=this.pic[i][j];
  115.  
  116. }
  117. }
  118.  
  119. for (int j = 0; j<this.columns; j++){
  120. for (int i=0; i<this.rows; i++){
  121. this.pic[i][j]=EZER[EZER.length-i][EZER[0].length-j];
  122. }
  123. }
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement