7. แถวลำดับ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 7-30  เมท็อดการพลิกภาพตามแนวนอน
import jlab.graphics.DWindow;
public class ImageProc {
  public static void main(String[] args) {
    DWindow w = new DWindow();
    w.loadImage("c:/java101/monument.jpg");
    int[][] p = w.getPixmap();
    int[][] flip = horizontalFlip(p);
    w.setPixmap(flip);
  }
  public static int[][] horizontalFlip(int[][] p) {
    int[][] out = new int[p.length][p[0].length];
    for (int x = 0; x < p.length; x++) {
      for (int y = 0; y < p[0].length; y++) {
        out[x][y] = p[p.length - x - 1][y];
      }
    }
    return out;
  }
©2009 S.Prasitjutrakul