📄 ch7.htm
字号:
2);<BR> biHeight = pullVal(is,2);<BR> biPlanes = pullVal(is,2);<BR> biBitCount = pullVal(is,2);<BR> extractColorMap(is,0);<BR> }<BR><BR> /**<BR> * A private method for extracting a Windowsstyle<BR> * bitmap header.<BR> * @param is contains the input stream<BR> */<BR> private void extractWindowsStyle(DataInputStreamis)<BR> throws IOException,AWTException<BR> {<BR> windowsStyle =true;<BR> biWidth = pullVal(is,4);<BR> biHeight = pullVal(is,4);<BR> biPlanes = pullVal(is,2);<BR> biBitCount = pullVal(is,2);<BR> biCompression= pullVal(is, 4);<BR> biSizeImage =pullVal(is, 4);<BR> biXPelsPerMeter= pullVal(is, 4);<BR> biYPelsPerMeter= pullVal(is, 4);<BR> biClrUsed = pullVal(is,4);<BR> biClrImportant= pullVal(is, 4);<BR> extractColorMap(is,biClrUsed);<BR> }<BR><BR> /**<BR> * A private method for extracting thebitmap header.<BR> * This method determines the header type(OS/2 or Windows)<BR> * and calls the appropriate routine.<BR> * @param is contains the input stream<BR> */<BR> private void extractBitmapHeader(DataInputStreamis)<BR> throws IOException,AWTException<BR> {<BR> biSize = pullVal(is,4);<BR> if ( biSize ==12 )<BR> extractOS2Style(is);<BR> else<BR> extractWindowsStyle(is);<BR> }<BR><BR> /**<BR> * A private method for extracting 4 bitper pixel<BR> * image data.<BR> * @param is contains the input stream<BR> */<BR> private void extract4BitData( DataInputStreamis )<BR> throws IOException<BR> {<BR> int index, temp= 0;<BR><BR> if ( biCompression== 0 )<BR> {<BR> intpadding = 0;<BR> intoverage = ((biWidth + 1)/ 2) % 4;<BR> if( overage != 0 )<BR> padding= 4 - overage;<BR> pix= new int[biHeight * biWidth];<BR> for( int y = biHeight - 1; y >= 0; y-- )<BR> {<BR> index= y * biWidth;<BR> for( int x = 0; x < biWidth; x++ )<BR> {<BR> //if on an even byte, read new 8 bit quantity<BR> //use low nibble of previous read for odd bytes<BR> if( (x % 2) == 0 )<BR> {<BR> temp= is.readUnsignedByte();<BR> pix[index++]= temp >> 4;<BR> }<BR> else<BR> pix[index++]= temp & 0x0f;<BR> }<BR> if( padding != 0 ) is.skipBytes(padding);<BR> }<BR> }<BR> else<BR> {<BR> thrownew IOException("Compressed images not supported");<BR> }<BR> }<BR><BR> /**<BR> * A private method for extracting 8 bitper pixel<BR> * image data.<BR> * @param is contains the input stream<BR> */<BR> private void extract8BitData( DataInputStreamis )<BR> throws IOException<BR> {<BR> int index;<BR><BR> if ( biCompression== 0 )<BR> {<BR> intpadding = 0;<BR> intoverage = biWidth % 4;<BR> if( overage != 0 )<BR> padding= 4 - overage;<BR> pix= new int[biHeight * biWidth];<BR> for( int y = biHeight - 1; y >= 0; y-- )<BR> {<BR> index= y * biWidth;<BR> for( int x = 0; x < biWidth; x++ )<BR> {<BR> pix[index++]= is.readUnsignedByte();<BR> }<BR> if( padding != 0 ) is.skipBytes(padding);<BR> }<BR> }<BR> else<BR> {<BR> thrownew IOException("Compressed images not supported");<BR> }<BR> }<BR><BR> /**<BR> * A private method for extracting theimage data from<BR> * a input stream.<BR> * @param is contains the input stream<BR> */<BR> private void extractImageData( DataInputStreamis )<BR> throws IOException,AWTException<BR> {<BR> switch ( biBitCount)<BR> {<BR> case 1:<BR> thrownew AWTException("Unhandled bits/pixel: " + biBitCount);<BR> case 4: extract4BitData(is);break;<BR> case 8: extract8BitData(is);break;<BR> case 24:<BR> thrownew AWTException("Unhandled bits/pixel: " + biBitCount);<BR> default:<BR> thrownew AWTException("Invalid bits per pixel: " + biBitCount);<BR> }<BR> }<BR><BR> /**<BR> * Given an input stream, create an ImageProducerfrom<BR> * the BMP info contained in the stream.<BR> * @param is contains the input streamto use<BR> * @returns the ImageProducer<BR> */<BR> public ImageProducer extractImage( DataInputStreamis )<BR> throws AWTException<BR> {<BR> MemoryImageSourceimg = null;<BR> try<BR> {<BR> extractFileHeader(is);<BR> extractBitmapHeader(is);<BR> extractImageData(is);<BR> img= new MemoryImageSource( biWidth, biHeight, colorModel,<BR> pix, 0, biWidth );<BR> imageProcessed= true;<BR> }<BR> catch (IOExceptionioe )<BR> {<BR> thrownew AWTException(ioe.toString());<BR> }<BR> return img;<BR> }<BR><BR> /**<BR> * Describe the image as a string<BR> */<BR> public String toString()<BR> {<BR> StringBuffer buf= new StringBuffer("");<BR> if ( imageProcessed)<BR> {<BR> buf.append(" name: " + bfName + "\n");<BR> buf.append(" size: " + bfSize + "\n");<BR> buf.append("img offset: " + bfOffset + "\n");<BR> buf.append("headersize: " + biSize + "\n");<BR> buf.append(" width:" + biWidth + "\n");<BR> buf.append(" height: " + biHeight + "\n");<BR> buf.append("clr planes: " + biPlanes + "\n");<BR> buf.append("bits/pixel: " + biBitCount + "\n");<BR> if( windowsStyle )<BR> {<BR> buf.append("compression:" + biCompression + "\n");<BR> buf.append("image size: " + biSizeImage + "\n");<BR> &n
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -