/*********************************************************** 直接用FileInputStream、FileOutputStream處理二進位檔 ***********************************************************/ import java.io.*; public class demo29{ public static void main(String args[]) throws Exception { //程式進入點 String getbr,getfr; BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int i,j; int x,y,k; byte data[][][]=new byte[300][300][3];//300*300*3 byte 放輸入圖形 byte ndata[][][]=new byte[300][300][3];//300*300*3 byte 放轉過的圖形 byte header[]=new byte[54];//54位元表頭 /*****請使用者輸入檔案名稱**********/ System.out.print("請輸入來源bmp檔案名稱:"); getbr = br.readLine(); //取得input file FileInputStream fr=new FileInputStream(getbr);//開檔案 fr.read(header,0,54);//讀取54 byte表頭,由0開始,填入54byte for (i=0;i<300;i=i+1) for (j=0;j<300;j=j+1) fr.read(data[i][j],0,3);//讀取每一點,每一點三個byte fr.close();//關閉檔案 /****轉180度******/ for (x=0;x<300;x=x+1) for (y=0;y<300;y=y+1) for (k=0;k<3;k=k+1) { ndata[y][x][k]=data[299-y][x][k]; } /**** open input file *********/ System.out.print("請輸入目標檔案名稱:"); getbr = br.readLine(); //取得output file /**** open output file *********/ FileOutputStream fw=new FileOutputStream(getbr);//開檔案 fw.write(header,0,54);//寫入表頭,由0開始,寫出54byte for (i=0;i<300;i=i+1) for (j=0;j<300;j=j+1) fw.write(ndata[i][j],0,3);//寫入每一點,每點3 byte fw.close();//關閉檔案 } //main 結束 }