This piece of code above is to flip an image horizontally in Java, does anyone k
ID: 3875927 • Letter: T
Question
This piece of code above is to flip an image horizontally in Java, does anyone know how to write the code that flips image vertically? Thank you
//for each row, swap its contents from left to right for (int row = 0; row the Image. getHeight(); row++) { for (int col = 0; col the Image . getWidth ( ) / 2; col++) { // given a column: i, its pair is column: vidth) - i - 1 /1 e.g. with a vidth of 10 /colunn 0 is paired vith column 9 I column 1 is paired vith column 8 etc. Pixel temp = data[row][col]; data[row] [ col] data[row] [the Image . getWidth () -col -j; data[row] [ the Image. getWidth() - col -j = temp ; update the image vith the moved pixels theImage.setData(data)Explanation / Answer
Hi, The code to flip vertically is almost similar
for(int col=0;i<theImage.getWidth();col++){
for(int row=0;row<theImage.getHeight()/2;row++){
Pixel temp = data[row][col];
data[row][col] = data[theImage.getHeight()-row-1][col];
data[theImage.getHeight()-row-1][col] = temp;
}
}
theImage.setData(data)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.