?? imagetogif.java
字號:
continue; } pixCol[k2] = word0; break; } } } catch (Exception ex) { return false; } return true; } /** *@param word0 Description of the Parameter *@return Description of the Return * Value */ public boolean lzwOutput(short word0) { try { lzwData |= (word0 << lzwBits); for (lzwBits += sActCodeSize; lzwBits >= 8;) { Block[BlockPos++] = (byte) (lzwData & 0xff); Block[0]++; lzwData >>= 8; lzwBits -= 8; if (BlockPos == 256) { for (int i = 0; i < 256; i++) { dataOut.writeByte(Block[i]); } Block[0] = 0; BlockPos = 1; } } return true; } catch (Exception ex) { return false; } } /** *@return Description of * the Return Value *@throws IOException Description of * the Exception */ public boolean openGif() throws IOException { try { dataOut = new DataOutputStream(output); } catch (Exception ex) { return false; } return true; } /** */ public void startProc() { try { code = new short[5003]; prefix = new short[5003]; codeCharacter = new short[5003]; Block = new short[256]; if ((image != null) && getImageInfo() && openGif() && calcGif()) { if (closeGif()) { if (message) { System.out.println("\n Picture is available!"); return; } } else if (message) { System.out.println("\n Error, Picture is NOT available!"); } return; } } catch (Exception exception) { System.out.println(String.valueOf(exception)); } } /** *@return Description of the Return * Value */ public boolean writeDataBlocks() { int[] ai = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191 }; try { int j = (flagLSD & 0x7) + 1; if (j > 2) { sOriginalCodeSize = (short) j; } else { sOriginalCodeSize = 2; } dataOut.writeByte((byte) sOriginalCodeSize); CalcSpecialCodes(); ClearCompressionTable(); Block[0] = 0; BlockPos = 1; lzwData = 0; lzwBits = 0; if (!lzwOutput(clearCode)) { return false; } int l = 0; int i = l * imgWidth; short word3 = (short) (pixCol[i++] & 0xff); int k = 1; while (l < imgHeight) { short word2 = pixCol[i++]; short word0 = FindSlot(word3, word2); if (code[word0] != -1) { word3 = code[word0]; } else { if (freeSlot <= (ai[sActCodeSize] + 1)) { code[word0] = freeSlot++; prefix[word0] = word3; codeCharacter[word0] = word2; } if (!lzwOutput(word3)) { return false; } word3 = word2; if ((freeSlot > (ai[sActCodeSize] + 1)) || (freeSlot == 4096)) { if (sActCodeSize < 12) { sActCodeSize++; } else { if (!lzwOutput(clearCode)) { return false; } sActCodeSize = sOriginalCodeSize; CalcSpecialCodes(); ClearCompressionTable(); } } } if (++k == imgWidth) { k = 0; if (++l < imgHeight) { i = l * imgWidth; } } } if (!lzwOutput(word3)) { return false; } if (!lzwOutput((short) 0)) { return false; } if (!lzwOutput(endCode)) { return false; } if (!lzwOutput((short) 0)) { return false; } if (Block[0] != 0) { dataOut.writeByte(Block[0]); for (short word1 = 1; word1 <= Block[0];) { dataOut.writeByte(Block[word1++]); } dataOut.writeByte(0); } return true; } catch (Exception ex) { return false; } } /** *@return Description of the Return * Value */ public boolean writeGlobalPalette() { int j = 1; for (int i = palSize - 1; (i >>= 1) > 0;) { j++; } try { for (int k = 0; k < palSize; k++) { Color color = new Color(palArr[k]); dataOut.writeByte(color.getRed()); dataOut.writeByte(color.getGreen()); dataOut.writeByte(color.getBlue()); } for (int l = palSize; l < (1 << j); l++) { Color color1 = new Color(palArr[0]); dataOut.writeByte(color1.getRed()); dataOut.writeByte(color1.getGreen()); dataOut.writeByte(color1.getBlue()); } } catch (Exception ex) { return false; } return true; } /** *@return Description of the Return * Value */ public boolean writeHeader() { try { dataOut.writeBytes("GIF87a"); } catch (Exception ex) { return false; } return true; } /** *@return Description of the Return * Value */ public boolean writeImageDescriptor() { try { byte byte0 = (byte) (flagLSD & 0x7); dataOut.writeByte(44); dataOut.writeChar(0); dataOut.writeChar(0); dataOut.writeChar(MSBtoLSB(imgWidth)); dataOut.writeChar(MSBtoLSB(imgHeight)); dataOut.writeByte(byte0); } catch (Exception ex) { return false; } return true; } /** *@return Description of the Return * Value */ public boolean writeLSD() { byte byte0 = 0; int i = palSize - 1; try { while ((i >>= 1) > 0) { byte0++; } flagLSD = (byte) (((byte0 + 8) << 4) + byte0); dataOut.writeChar(MSBtoLSB(imgWidth)); dataOut.writeChar(MSBtoLSB(imgHeight)); dataOut.writeByte(flagLSD); dataOut.writeByte(0); dataOut.writeByte(0); } catch (Exception ex) { return false; } return true; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -