2013-07-05 67 views
0

是否有任何庫,它可以採取現有的動畫GIF文件和設置/取消設置循環計數和循環標誌?我有幾個由FFMPEG生成的GIF文件,並且似乎無法將循環/循環計數標誌設置爲FFMPEG。所以需要某種後處理的GIF圖像。修改GIF89A文件標題

回答

1

解決方案(中階)就是這麼簡單:

val raf = new RandomAccessFile(src, "rw") 
    // skip GIF header, 6 bytes. Don't care of it much. 
    raf.skipBytes(6) 
    // don't need image dimension 
    raf.skipBytes(4) 
    val flags = raf.readUnsignedByte() 
    val headerSize = 3 * (1 << ((flags & 7) + 1)) // 00000111 - size of color table 
    val headerExists = flags & 128 // 10000000 - is there a color table at all 
    // skip background color and pixel ratio 
    raf.skipBytes(2) 
    if (headerExists != 0) { 
    raf.skipBytes(headerSize) 
    } 
    val signature = raf.readUnsignedShort() 
    require(signature == 0x21ff) 
    raf.skipBytes(13) // NETSCAPE 2.0 
    raf.skipBytes(1) // GIF animation flag has to be 1 
    ctx.loopCount.foreach { 
    v => 
     raf.writeByte(v & 0xff) 
     raf.writeByte((v >> 8) & 0xff) 
    } 
    raf.close() 
+0

可以將其轉換成Java?謝謝 – rgomesf