Re: [問題] 還是.bmp檔案的問題 ~"~

看板java作者 (放火後ティータイム)時間13年前 (2012/03/13 21:59), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/7 (看更多)
遇到一樣的問題,還是想讀八位元的灰階圖,結果用當初寫的RGB讀24位元的class去讀 ,取灰階後亮度整個變亮跟原圖差距太大 參考了之前回文那位前輩的想法用Raster的getData()這個API的想法 因為懶得把原來的程式大改就自己照NetBean編碼上面函式的註解亂踹 我改成下面的取法: file=new File(Filename); Input= ImageIO.read(file); height=Input.getHeight(); width=Input.getWidth(); gray=new int[height][width]; Raster tmpRas; tmpRas=Input.getData(); //因為看getData()這個函式說會回傳一個Raster類別的物件,想說姑且先宣告一個參考 //讓這個函式的回傳指給他,再看看這個參考下面有甚麼可用的函式 for(int i=0;i<height;i++) for(int j=0;j<width;j++) gray[i][j]=tmpRas.getSample(j, i, 0); //我找到getSample這個函式,想法很簡單,想看Raster是不是可以定位原圖裡面的各 //pixel裡面的值,這個函式的註解如下: public int getSample(int x, int y, int b) Returns the sample in a specified band for the pixel located at (x,y) as an int. An ArrayIndexOutOfBoundsException may be thrown if the coordinates are not in bounds. However, explicit bounds checking is not guaranteed. 參數: x - The X coordinate of the pixel location y - The Y coordinate of the pixel location b - The band to return 回傳: the sample in the specified band for the pixel at the specified coordinate. 拋出: ArrayIndexOutOfBoundsException - if the coordinates or the band index are not in bounds. 我很好奇這裡提到的band這個參數是甚麼,去網路翻使用範例,似乎有0或1或2這三種用例 不過試過之後只有丟0進去可以通過編譯 得出來的結果我的情形是可以得到不會改變原8位元圖亮度的24位元灰階圖 關於這個band不知道有沒有高手能解答是甚麼 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 175.182.2.45
文章代碼(AID): #1FNrB7m3 (java)
討論串 (同標題文章)
文章代碼(AID): #1FNrB7m3 (java)