Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RGBImage {
- private int columns;
- private int rows;
- private RGBColor[][]pic;
- public RGBImage(int rows, int cols){
- this.columns=cols;
- this.rows=rows;
- pic=new RGBColor[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- pic[i][j]=new RGBColor();
- }
- }
- }
- public RGBImage(RGBColor[][]pixels){
- pic=new RGBColor[pixels.length][pixels[0].length];
- for (int i = 0; i < pixels.length; i++) {
- for (int j = 0; j < pixels[0].length; j++) {
- pic[i][j]= new RGBColor (pixels[i][j]);
- }
- }
- }
- public RGBImage(RGBImage other){
- int cols=other.getPic().length;
- int rows=other.getPic()[0].length;
- pic=new RGBColor[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- pic[i][j]=other.getPic()[i][j];
- }
- }
- }
- public int getWidth() {
- return columns;
- }
- public void setcolumns(int columns) {
- this.columns = columns;
- }
- public int getHeight() {
- return rows;
- }
- public void setRows(int rows) {
- this.rows = rows;
- }
- public RGBColor[][] getPic() {
- return this.pic;
- }
- public void setPic(RGBColor[][] pic) {
- this.pic = pic;
- }
- /*public void toStrin(){
- for (int i = 0; i < columns; i++) {
- for (int j = 0; j < rows; j++) {
- System.out.println(pic[i][j].getBlue()+", "+pic[i][j].getGreen()+", "+pic[i][j].getRed());
- }
- }
- }
- */
- public RGBColor getPixel (int rows, int cols){
- if (this.rows>=rows||this.columns>=cols)
- return this.pic[rows][cols];
- else
- return new RGBColor();
- }
- public void setPixel (int row, int col, RGBColor pixel){
- this.pic[row][col]= new RGBColor (pixel);
- }
- public boolean equales (RGBImage other){
- if (this.columns==other.columns&&this.rows==other.rows&&ifif(other.getPic())){
- return true;
- }
- return false;
- }
- private boolean ifif (RGBColor[][] other){
- for (int i = 0; i < other.length; i++) {
- for (int j = 0; j < other[0].length; j++) {
- if (!this.pic[i][j].equals(other[i][j]))
- return false;
- }
- }
- return true;
- }
- public void flipHorizontal (){
- RGBColor[][] EZER = new RGBColor[this.columns][this.rows];
- for (int i = 0; i<this.columns; i++){
- for (int j=0; j<this.rows; j++){
- EZER[i][j]=this.pic[i][j];
- }
- }
- for (int j = 0; j<this.columns; j++){
- for (int i=0; i<this.rows; i++){
- this.pic[i][j]=EZER[EZER.length-i][EZER[0].length-j];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement