亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? gifencoder.java

?? 在java中處理gif文件的編碼例子
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/**
 * Strictly speaking, it is against patent laws to produce unlicensed
 * GIF images.  See http://www.unisys.com for license agreements.
 * Without such a license, the use of a class similar to the following
 * would be prohibited.
 *
 * --
 * Greg Faron
 * Integre Technical Publishing Co.
 */

import java.awt.AWTException;
import java.awt.Image;
import java.awt.image.PixelGrabber;
import java.io.IOException;
import java.io.OutputStream;

/**
 * Class <CODE>GIFEncoder</CODE> takes an <CODE>Image</CODE> and
 * saves it to a file using the <CODE>GIF</CODE> file format
 * (<A HREF="http://www.dcs.ed.ac.uk/%7Emxr/gfx/">Graphics Interchange
 * Format</A>).
 * A <CODE>GIFEncoder</CODE> object is constructed with either an
 * <CODE>Image</CODE> object (which must be fully loaded), or a set of
 * three 2-dimensional <CODE>byte</CODE> arrays.  The image file can be
 * written out with a call to {@link #write(OutputStream) write()}.<p>
 * Three caveats:
 * <UL>
 * <LI>Class <CODE>GIFEncoder</CODE> will convert the image to
 * indexed color upon
 * construction.  This will take some time, depending on the size of
 * the image.
 * Also, the act of writing the image to disk will take some
 * time.</LI>
 * <LI>The image cannot have more than 256 colors, since GIF is an 8
 * bit format.  For a 24 bit to 8 bit quantization algorithm, see
 * Graphics Gems II III.2 by <A
 * HREF="http://www.csd.uwo.ca/faculty/wu/">Xialoin Wu</A>.
 * Or check out his <A HREF="http://www.csd.uwo.ca/faculty/wu/cq.c">C
 * source</A>.</LI>
 * <LI>Since the image must be completely loaded into memory,
 * <CODE>GIFEncoder</CODE>
 * may have problems with large images.  Attempting to encode an
 * image which will not
 * fit into memory will probably result in the following
 * exception:<BR>
 * <CODE>java.awt.AWTException: Grabber returned false:
 * 192</CODE></LI>
 * </UL>
 * <CODE>GIFEncoder</CODE> is based upon gifsave.c, which was written
 * and released by:<p>
 * <DIV ALIGN="CENTER">
 * Sverre H. Huseby<BR>
 * Bjoelsengt. 17<BR>
 * N-0468 Oslo<BR>
 * Norway<p>
 * Phone: +47 2 230539<BR>
 * <A HREF="mailto:sverrehu@ifi.uio.no">sverrehu@ifi.uio.no</A><BR>
 * </DIV>
 *
 * @author Adam Doppelt (dead link <A
 * @author Greg Faron - Integre Technical Publishing -
 * @version 0.90 21 Apr 1996
 */
public class GIFEncoder extends Object
   {
   /**
    * image height in pixels
    */
   short imageWidth, imageHeight;
   /**
    * number of different colours in image
    */
   int numberOfColors;
   /**
    * linear array of all pixels in row major order.
    */
   byte[] allPixels = null;
   /**
    * list of all colours used in the image.
    */
   byte[] allColors = null;

   /**
    * Convenience constructor for class <CODE>GIFEncoder</CODE>.  The
    * argument will
    * be converted to an indexed color array.
    * <B>This may take some time.</B>
    *
    * @param image  The image to encode. The image <B>must</B> be
    *               completely loaded.
    * @exception AWTException
    *                   Will be thrown if the pixel grab fails.
    *                   This can happen
    *                   if Java runs out of memory.  It may also
    *                   indicate that the
    *                   image contains more than 256 colors.
    */
   public GIFEncoder( Image image )
   throws AWTException
   {
      this.imageWidth = (short )image.getWidth( null );
      this.imageHeight = (short )image.getHeight( null );

      int values[] = new int[this.imageWidth * this.imageHeight];
      PixelGrabber grabber = new PixelGrabber( image,
                                               0, 0,
                                               this.imageWidth,
                                               this.imageHeight,
                                               values, 0, this.imageWidth );

      try
         {
         if ( grabber.grabPixels( ) != true )
            throw new AWTException( "Grabber returned false: " +
                                    grabber.status( ) );
         } // ends try

      catch ( InterruptedException ie )
         {
         }

      byte[][] r = new byte[this.imageWidth][this.imageHeight];
      byte[][] g = new byte[this.imageWidth][this.imageHeight];
      byte[][] b = new byte[this.imageWidth][this.imageHeight];
      int index = 0;

      for ( int y=0; y<this.imageHeight; y++ )
         {
         for ( int x=0; x<this.imageWidth; x++, index++ )
            {
            r[x][y] = (byte)( ( values[index] >> 16 ) & 0xFF );
            g[x][y] = (byte)( ( values[index] >> 8 ) & 0xFF );
            b[x][y] = (byte)( ( values[index] ) & 0xFF );
            } // ends for

         } // ends for

      this.toIndexColor( r, g, b );
   } // ends constructor GIFEncoder(Image )

   /** Standard constructor for class <CODE>GIFEncoder</CODE>.
     * Each array stores intensity
     * values for the image.  In other words,
     * <NOBR><CODE>r[x][y]</CODE></NOBR> refers to
     * the red intensity of the pixel at column <CODE>x</CODE>, row
     * <CODE>y</CODE>.
     * @param r A 2-dimensional array containing the red intensity values.
     * @param g A 2-dimensional array containing the green intensity
     * values.
     * @param b A 2-dimensional array containing the blue intensity values.
     * @exception AWTException Thrown if the image contains more than 256
     * colors.
     */
   public GIFEncoder( byte[][] r, byte[][] g, byte[][] b )
   throws AWTException
   {
      this.imageWidth = (short )( r.length );
      this.imageHeight = (short )( r[0].length );

      this.toIndexColor( r, g, b );
   } // ends constructor GIFEncoder(byte[][], byte[][], byte[][] )

   /** Writes the image out to a stream in the <CODE>GIF</CODE> file
     * format.
     * This will be a single GIF87a image, non-interlaced, with no
     * background color.
     * <B>This may take some time.</B>
     * @param output The stream to which to output. This should probably be
     * a buffered stream.
     * @exception IOException Thrown if a write operation fails.
     */
   public void write( OutputStream output )
   throws IOException
   {
      BitUtils.writeString( output, "GIF87a" );
      ScreenDescriptor sd = new ScreenDescriptor( this.imageWidth,
                                                  this.imageHeight, this.numberOfColors );
      sd.write( output );

      output.write( this.allColors, 0, this.allColors.length) ;

      ImageDescriptor id = new ImageDescriptor( this.imageWidth, this.imageHeight, ',' );
      id.write( output );

      byte codesize = BitUtils.BitsNeeded(this.numberOfColors);
      if ( codesize == 1 )
         {
         codesize ++;
         }
      output.write( codesize );

      LZWCompressor.LZWCompress( output, codesize, this.allPixels );
      output.write( 0 );

      id = new ImageDescriptor( (byte)0, (byte)0, ';' );
      id.write( output );
      output.flush();
   } // ends write( OutputStream )

   /**
    * Converts rgb desrcription of image to colour
    * number description used by GIF.
    *
    * @param r      red array of pixels
    * @param g      green array of pixels
    * @param b      blue array of pixels
    * @exception AWTException
    *                   Thrown if
    *                   too many different colours in image.
    */
   void toIndexColor( byte[][] r, byte[][] g, byte[][] b )
   throws AWTException
   {
      this.allPixels = new byte[this.imageWidth * this.imageHeight];
      this.allColors = new byte[256 * 3];
      int colornum = 0;
      for ( int x=0; x<this.imageWidth; x++ )
         {
         for ( int y=0; y<this.imageHeight; y++ )
            {
            int search;
            for ( search=0; search < colornum; search++ )
               {
               if ( this.allColors[search * 3] == r[x][y] &&
                    this.allColors[search * 3 + 1] == g[x][y] &&
                    this.allColors[search * 3 + 2] == b[x][y] )
                  {
                  break;
                  } // ends if

               } // ends for

            if ( search > 255 )
               throw new AWTException( "Too many colors." );
            // row major order y=row x=col
            this.allPixels[y * this.imageWidth + x] = (byte)search;

            if ( search == colornum )
               {
               this.allColors[search * 3] = r[x][y]; // [col][row]
               this.allColors[search * 3 + 1] = g[x][y];
               this.allColors[search * 3 + 2] = b[x][y];
               colornum++;
               } // ends if

            } // ends for

         } // ends for

      this.numberOfColors = 1 << BitUtils.BitsNeeded( colornum );
      byte copy[] = new byte[this.numberOfColors * 3];
      System.arraycopy( this.allColors, 0, copy, 0, this.numberOfColors * 3 );
      this.allColors = copy;
   } // ends toIndexColor(byte[][], byte[][], byte[][] )

   } // ends class GIFEncoder

/**
 * Used to write the bits composing the GIF image.
 */
class BitFile extends Object
   {
   /**
    * The outputstream where the data is written.
    */
   OutputStream output = null;
   /**
    * buffer for bits to write.
    */
   byte[] buffer;
   /**
    */
   int indexIntoOutputStream, bitsLeft;

   /**
    * constructor
    *
    * @param output Where image will be written
    */
   public BitFile( OutputStream output )
      {
      this.output = output;
      this.buffer = new byte[256];
      this.indexIntoOutputStream = 0;
      this.bitsLeft = 8;
      } // ends constructor BitFile(OutputStream )

   /**
    * Ensures image in ram gets to disk.
    *
    * @exception IOException
    */
   public void flush( )
   throws IOException
   {
      int numBytes = this.indexIntoOutputStream + ( (this.bitsLeft == 8 ) ? 0 : 1 );
      if ( numBytes > 0 )
         {
         this.output.write( numBytes );
         this.output.write( this.buffer, 0, numBytes );
         this.buffer[0] = 0;
         this.indexIntoOutputStream = 0;
         this.bitsLeft = 8;
         } // ends if

   } // ends flush( void )

   /**
    * Write bits to stream.
    *
    * @param bits    source of bits, low/high order?
    * @param numbits how many bits to write.
    *
    * @exception IOException
    */
   public void writeBits( int bits, int numbits )
   throws IOException
   {
      int bitsWritten = 0;
      int numBytes = 255;
      do
         {
         if ( (this.indexIntoOutputStream == 254 && this.bitsLeft == 0 ) ||
              this.indexIntoOutputStream > 254 )
            {
            this.output.write( numBytes );
            this.output.write( this.buffer, 0, numBytes );

            this.buffer[0] = 0;
            this.indexIntoOutputStream = 0;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区丝袜| 欧美日韩一区二区在线视频| 欧美日韩一区视频| 国产精品国产三级国产三级人妇| 另类小说欧美激情| 欧美一区二区在线免费播放| 亚洲一区二区偷拍精品| 色婷婷久久久综合中文字幕| 日本一区二区视频在线观看| 国产成人a级片| 久久综合九色综合97婷婷女人| 免费成人av在线播放| 日韩欧美国产1| 美女一区二区三区在线观看| 日韩欧美视频在线| 精品综合免费视频观看| 欧美电影免费观看高清完整版在线观看 | 青青草伊人久久| 在线观看91视频| 欧美mv和日韩mv国产网站| 美女高潮久久久| 精品久久久久久综合日本欧美| 乱一区二区av| 欧美mv和日韩mv国产网站| 国产精品一二三区在线| 国产亚洲欧美中文| 99精品久久99久久久久| 亚洲一区二区三区四区五区中文| 94-欧美-setu| 亚洲一线二线三线久久久| 欧美电影一区二区| 亚洲欧美一区二区三区孕妇| 日本韩国一区二区三区视频| 亚洲一区在线免费观看| 欧美一区二区在线播放| 国产经典欧美精品| 亚洲日本电影在线| 欧美精品1区2区| 国产一区二区91| 欧美国产精品中文字幕| 欧美性色aⅴ视频一区日韩精品| 亚洲成av人片www| 久久你懂得1024| 91视频一区二区三区| 免费美女久久99| 中文字幕制服丝袜成人av| 色综合久久99| 久久精品72免费观看| 国产精品国产三级国产普通话三级| 欧美日韩中文一区| 国产风韵犹存在线视精品| 亚洲与欧洲av电影| 久久久精品天堂| 97se狠狠狠综合亚洲狠狠| 麻豆极品一区二区三区| 亚洲精品欧美在线| 中文字幕一区二区三区四区不卡| 成人免费视频播放| 日韩精品电影一区亚洲| 中文文精品字幕一区二区| 色狠狠av一区二区三区| 国产一区日韩二区欧美三区| 亚洲一区二区在线免费观看视频 | 欧美喷水一区二区| 国产美女一区二区| 亚洲成av人在线观看| 中文字幕成人av| 欧美一区二区三区婷婷月色| 99久久久久久| 精品中文字幕一区二区小辣椒| 国产精品不卡在线观看| 精品乱码亚洲一区二区不卡| 欧美日韩国产经典色站一区二区三区| 成人福利视频在线看| 蜜臀91精品一区二区三区| 亚洲视频一二三| 国产欧美日韩三区| 日韩欧美123| 欧美精品一卡二卡| 色婷婷av一区| www.欧美色图| 国产风韵犹存在线视精品| 天堂精品中文字幕在线| 亚洲精品中文字幕在线观看| 国产精品少妇自拍| 国产日产欧美一区二区视频| 欧美成人猛片aaaaaaa| 欧美一区二区三区色| 91在线免费播放| av在线不卡网| 成人久久18免费网站麻豆| 国产精品一区二区三区网站| 久88久久88久久久| 免费人成在线不卡| 日韩二区三区四区| 日韩电影一区二区三区四区| 午夜久久久久久久久| 亚洲成人免费视| 午夜激情一区二区三区| 亚洲国产日韩一级| 日欧美一区二区| 天天色天天操综合| 亚洲欧美视频一区| 亚洲黄一区二区三区| 亚洲九九爱视频| 亚洲一区二区三区国产| 亚洲成av人片在线观看无码| 午夜久久久影院| 麻豆精品在线视频| 激情文学综合丁香| 成人精品国产一区二区4080| 成人激情开心网| 97久久精品人人做人人爽| 色婷婷av一区二区三区大白胸| eeuss鲁片一区二区三区在线观看| 91在线小视频| 欧美人体做爰大胆视频| 日韩欧美成人激情| 久久久久88色偷偷免费 | 欧美一区二区免费| 久久婷婷综合激情| 国产精品国产三级国产aⅴ中文 | 精品视频在线免费看| 久久精品无码一区二区三区| 337p粉嫩大胆噜噜噜噜噜91av| 中文字幕综合网| 蜜桃91丨九色丨蝌蚪91桃色| 波多野洁衣一区| 日韩精品一区二区三区四区| 亚洲免费色视频| 国产在线麻豆精品观看| 欧美性受xxxx| 中文字幕在线一区免费| 久久精品噜噜噜成人88aⅴ| 91免费版pro下载短视频| 精品国产乱码久久久久久老虎| 一区二区三区在线免费观看| 国产成人免费av在线| 日韩欧美在线影院| 性做久久久久久久免费看| 成人av电影在线| 欧美成人aa大片| 亚洲成人自拍一区| 色婷婷亚洲一区二区三区| 国产亚洲一区二区三区在线观看 | 蜜桃精品视频在线| 在线国产电影不卡| 国产精品久久久久久久久久免费看| 日韩不卡一区二区三区| 色噜噜狠狠一区二区三区果冻| 久久婷婷国产综合精品青草 | 老司机精品视频线观看86| 在线精品视频一区二区三四| 国产精品国产三级国产专播品爱网 | 欧美麻豆精品久久久久久| 18欧美亚洲精品| 国产精品99久久久| 欧美精品一区在线观看| 日本亚洲三级在线| 欧美日本一道本在线视频| 亚洲午夜一二三区视频| 91视频免费播放| 国产精品每日更新| 成人午夜精品一区二区三区| 久久综合九色综合97_久久久| 麻豆视频一区二区| 日韩欧美一区二区三区在线| 午夜激情综合网| 欧美高清视频www夜色资源网| 有码一区二区三区| 色屁屁一区二区| 亚洲欧洲制服丝袜| 在线观看亚洲专区| 夜夜爽夜夜爽精品视频| 欧美亚日韩国产aⅴ精品中极品| 亚洲日本va午夜在线电影| 91啪在线观看| 亚洲一区在线播放| 欧美日韩国产欧美日美国产精品| 亚洲国产成人av网| 欧美巨大另类极品videosbest | 欧美一区二区精品| 男女男精品网站| 精品国产一区二区三区不卡 | 久久久精品免费观看| 国产ts人妖一区二区| 国产精品你懂的| 久久精品国产亚洲a| 精品国产一区二区三区四区四| 国产一区二区日韩精品| 国产精品美女久久久久高潮| 色综合色综合色综合| 亚洲第一主播视频| 精品日产卡一卡二卡麻豆| 国产精品一区二区你懂的| 国产精品久久看| 欧美视频在线观看一区| 蜜桃精品视频在线| 国产精品美女久久久久久2018| 色综合中文综合网|