作者Makoto0813 (放火後ティータイム)
看板java
标题Re: [问题] 还是.bmp档案的问题 ~"~
时间Tue Mar 13 21:59:31 2012
遇到一样的问题,还是想读八位元的灰阶图,结果用当初写的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