有没有办法改变Gif速度

时间:2019-02-12 23:19:54

标签: java gif

尽管我不太确定如何使用Java更改gif速度,我想尝试以gif速度保存保存,可能会弹出一个带有速度选择的框。

我查了一下,但无济于事。我是新手,如果这是一个问题,我很抱歉,但我找不到它


import base.AnimationExporter;
import java.awt.Dimension;
import java.awt.Graphics;
import settings.GuiDrawer;

public class SaveButton extends GuiElement
{
  public SaveButton(GuiMenu parent)
  {
    super(parent);
  }

  public void releasedOn(int posX, int posY, int button)
  {
    if (heldDown) {
      heldDown = false;
      AnimationExporter.saveAnimation(true);
    }
  }

}

编辑:我最讨厌的动画导出器

   try {
     ImageWriter gifWriter = (ImageWriter)ImageIO.getImageWritersByFormatName("gif").next();
     ImageOutputStream outputStream = ImageIO.createImageOutputStream(outputFile);
     gifWriter.setOutput(outputStream);

     ImageTypeSpecifier imageType = ImageTypeSpecifier.createFromBufferedImageType(2);
     IIOMetadata metadata = gifWriter.getDefaultImageMetadata(imageType, null);
     IIOMetadataNode nodeTree = (IIOMetadataNode)metadata.getAsTree(metadata.getNativeMetadataFormatName());

     IIOMetadataNode appExtensionsNode = getNode("ApplicationExtensions", nodeTree);
     IIOMetadataNode child = new IIOMetadataNode("ApplicationExtension");
     child.setAttribute("applicationID", "NETSCAPE");
     child.setAttribute("authenticationCode", "2.0");

     child.setUserObject(new byte[] { 1, (byte)((Editing.animationLoop ? 0 : 1) & 0xFF), (byte)((Editing.animationLoop ? 0 : 1) >> 8 & 0xFF) });
     appExtensionsNode.appendChild(child);

     metadata.setFromTree(metadata.getNativeMetadataFormatName(), nodeTree);

     gifWriter.prepareWriteSequence(null);
     for (Frame frame : animation.Animation.frames) {
       IIOMetadata imageMetadata = gifWriter.getDefaultImageMetadata(imageType, null);
       IIOMetadataNode imageNodeTree = (IIOMetadataNode)imageMetadata.getAsTree(imageMetadata.getNativeMetadataFormatName());
       IIOMetadataNode graphicNode = getNode("GraphicControlExtension", imageNodeTree);
       graphicNode.setAttribute("disposalMethod", "none");
       graphicNode.setAttribute("userInputFlag", "FALSE");
       graphicNode.setAttribute("delayTime", Integer.toString(delay));

       imageMetadata.setFromTree(imageMetadata.getNativeMetadataFormatName(), imageNodeTree);

       IIOImage currentImage = new IIOImage(frame.getEntireFrame(), null, imageMetadata);
       gifWriter.writeToSequence(currentImage, null);
     }
     gifWriter.endWriteSequence();
     outputStream.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }```

2 个答案:

答案 0 :(得分:0)

嵌入了“ GIF”的帧率。但是,您可以通过外部工具加快或降低速度。 Photoshop可能效果最好。 This工具可能会为您提供帮助。如果您需要动态更改帧速率,我们需要有关正在使用的库的更多信息。

答案 1 :(得分:0)

啊,很抱歉,我以为我抄袭的次数减少了,现在看来,delayTime真是愚蠢,

public int delay = Editing.frameDelay; 我认为frameDelay是我应该改变的 public static int frameDelay = 100;