發新話題

[JAVA] 直接用RandomAccessFile處理二進位檔

[JAVA] 直接用RandomAccessFile處理二進位檔

引用:
import java.io.*;
public class demo29a{
        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
            RandomAccessFile fp=new RandomAccessFile(getbr,"rw");
            fp.read(header,0,54);
            for (i=0;i<300;i=i+1)
                for (j=0;j<300;j=j+1)
                        fp.read(data[j],0,3);
           
            /****轉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];
               }
             fp.seek(54);//跳到表頭後面
             for (i=0;i<300;i=i+1)
                for (j=0;j<300;j=j+1)
                        fp.write(ndata[j],0,3);
             fp.close();
        } //main 結束
}

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。