我找到了两个源,它们在组合时可用于在保持动画的同时调整图像大小.
你可能猜到,你需要做的就是上传gif,使用Alex的代码将其转换为ImageFiles / BufferedImages数组,使用你的Graphics2D代码调整每个帧的大小(你需要为Alex’s添加一个setImage方法) ImageFrame类),然后使用Elliot的代码将数组转换为gif!这是我的样子:
public static void main( String[] args )
{
try {
File imageFile = new File( "InputFile" );
FileInputStream fiStream = new FileInputStream( imageFile );
ImageFrame[] frames = readGif( fiStream );
for( int i = 0; i < frames.length; i++ ){
//code to resize the image
BufferedImage image = ImageUtilities.resizeImage( frames[ i ].getImage(),newWidth,newHeight);
frames[ i ].setImage( image );
}
ImageOutputStream output =
new FileImageOutputStream( new File( "OutputFile" ) );
GifSequenceWriter writer =
new GifSequenceWriter( output,frames[0].getImage().getType(),frames[0].getDelay(),true );
writer.writeToSequence( frames[0].getImage() );
for ( int i = 1; i < frames.length; i++ ) {
BufferedImage nextImage = frames[i].getImage();
writer.writeToSequence( nextImage );
}
writer.close();
output.close();
}
catch ( FileNotFoundException e ) {
System.out.println( "File not found" );
}
catch ( IOException e ) {
System.out.println( "IO Exception" );
}
}
然而,该代码不考虑具有在帧之间流逝的不同时间量的gif图像.