00000006.htm
来自「水木清华BBS」· HTM 代码 · 共 289 行 · 第 1/2 页
HTM
289 行
int i; <BR> int rowCount; <BR> int rowIndex; <BR> int lastRowIndex; <BR> int pad; <BR> int padCount; <BR> byte rgb [] = new byte [3]; <BR>// if a scanline is not time of 4, add some bytes <BR> size = (biWidth * biHeight) - 1; <BR> pad = ((biWidth * 3) % 4); <BR> if (pad != 0) <BR> pad = 4 - pad; <BR> rowCount = 1; <BR> padCount = 0; <BR> rowIndex = size - biWidth; <BR> lastRowIndex = rowIndex; <BR> <BR> try { <BR> for (j = 0; j < size; j++) { <BR> value = bitmap [rowIndex]; <BR> rgb [0] = (byte) (value & 0xFF); <BR> rgb [1] = (byte) ((value >> 8) & 0xFF); <BR> rgb [2] = (byte) ((value >> 16) & 0xFF); <BR> fo.write (rgb); <BR> if (rowCount == biWidth) { <BR> padCount += pad; <BR> for (i = 1; i <= pad; i++) <BR> fo.write (0x00); <BR> rowCount = 1; <BR> rowIndex = lastRowIndex - biWidth; <BR> lastRowIndex = rowIndex; <BR> } <BR> else <BR> rowCount++; <BR> rowIndex++; <BR> } <BR> <BR> //--- Update the size of the file <BR> bfSize += padCount - pad; <BR> biSizeImage += padCount - pad; <BR> } <BR> catch (Exception wb) { <BR> wb.printStackTrace (); <BR> } <BR> <BR> } <BR> <BR> /* <BR> * writeBitmapFileHeader writes the bitmap file header to the file. <BR> * <BR> */ <BR> private void writeBitmapFileHeader () { <BR> <BR> try { <BR> fo.write (bfType); <BR> fo.write (intToDWord (bfSize)); <BR> fo.write (intToWord (bfReserved1)); <BR> fo.write (intToWord (bfReserved2)); <BR> fo.write (intToDWord (bfOffBits)); <BR> <BR> } <BR> catch (Exception wbfh) { <BR> wbfh.printStackTrace (); <BR> } <BR> <BR> } <BR> <BR> /* <BR> * <BR> * writeBitmapInfoHeader writes the bitmap information header <BR> * to the file. <BR> * <BR> */ <BR> <BR> private void writeBitmapInfoHeader () { <BR> <BR> try { <BR> fo.write (intToDWord (biSize)); <BR> fo.write (intToDWord (biWidth)); <BR> fo.write (intToDWord (biHeight)); <BR> fo.write (intToWord (biPlanes)); <BR> fo.write (intToWord (biBitCount)); <BR> fo.write (intToDWord (biCompression)); <BR> fo.write (intToDWord (biSizeImage)); <BR> fo.write (intToDWord (biXPelsPerMeter)); <BR> fo.write (intToDWord (biYPelsPerMeter)); <BR> fo.write (intToDWord (biClrUsed)); <BR> fo.write (intToDWord (biClrImportant)); <BR> } <BR> catch (Exception wbih) { <BR> wbih.printStackTrace (); <BR> } <BR> <BR> } <BR> <BR> /* <BR> * <BR> * intToWord converts an int to a word, where the return <BR> * value is stored in a 2-byte array. <BR> * <BR> */ <BR> private byte [] intToWord (int parValue) { <BR> <BR> byte retValue [] = new byte [2]; <BR> <BR> retValue [0] = (byte) (parValue & 0x00FF); <BR> retValue [1] = (byte) ((parValue >> 8) & 0x00FF); <BR> <BR> return (retValue); <BR> <BR> } <BR> <BR> /* <BR> * <BR> * intToDWord converts an int to a double word, where the return <BR> * value is stored in a 4-byte array. <BR> * <BR> */ <BR> private byte [] intToDWord (int parValue) { <BR> <BR> byte retValue [] = new byte [4]; <BR> <BR> retValue [0] = (byte) (parValue & 0x00FF); <BR> retValue [1] = (byte) ((parValue >> 8) & 0x000000FF); <BR> retValue [2] = (byte) ((parValue >> 16) & 0x000000FF); <BR> retValue [3] = (byte) ((parValue >> 24) & 0x000000FF); <BR> <BR> return (retValue); <BR> <BR> } <BR> <BR>} <BR> <BR>-- <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 166.111.134.131] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?