package
test;
/** */ /**
* C-platform All Rights Reserved@2006-2007
* Author: hally
* Date: 2007-2-12
* Time: 19:48:43
* Modifier:hally
* Modify Date&Time: 2007-2-12 19:48:43
*/
import com.gif4j. * ;
import java.awt. * ;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class GifTest ... {
// Usage: java GifImageWatermarkExample [PathToGifImageToWatermark] (please be sure that the gif4j jar is in your CLASSPATH)
// By default the gif4j_logotype.gif as an example gif image is used
public static void main(String[] args) ...{
File gifImageFileToWatermark = null;
if (args.length == 0) ...{
gifImageFileToWatermark = new File("d:/1.gif ");
} else
gifImageFileToWatermark = new File(args[0]);
// load and decode gif image
GifImage gifImage = null;
try ...{
gifImage = GifDecoder.decode(gifImageFileToWatermark);
} catch (IOException e) ...{
e.printStackTrace();
System.exit(1);
}
// change out directory if it is necessary
File outputDir = new File("d:/result");
if (!outputDir.exists())
outputDir.mkdirs();
// create watermark image using TextPainter
TextPainter painter = new TextPainter(new Font("隶书", Font.BOLD, 25));
painter.setOutlinePaint(Color.WHITE);
painter.setForegroundPaint(Color.BLUE);
BufferedImage watermarkImage = painter.renderString("王海利", true);
// create watermark
Watermark watermark = new Watermark(watermarkImage, Watermark.LAYOUT_TOP_LEFT, 0.9f);
// apply watermark
GifImage topLeftWatermarked = watermark.apply(gifImage, true);
// apply watermark smoothly
GifImage topLeftWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
watermark.setLayoutConstraint(Watermark.LAYOUT_MIDDLE_CENTER);
// apply watermark
// GifImage middleCenterWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage middleCenterWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
// watermark.setLayoutConstraint(Watermark.LAYOUT_BOTTOM_RIGHT);
// apply watermark
// GifImage bottomRightWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage bottomRightWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
// watermark.setLayoutConstraint(Watermark.LAYOUT_COVER_CONSECUTIVELY);
// change the watermark transparency
// watermark.setTransparency(0.20f);
// apply watermark
// GifImage coverConsWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage coverConsWatermarked_smoothly = watermark.apply(gifImage, true);
// Save the results
try ...{
GifEncoder.encode(topLeftWatermarked, new File(outputDir, "topLeftWatermarked.gif"));
GifEncoder.encode(topLeftWatermarked_smoothly, new File(outputDir, "topLeftWatermarked_smooth.gif"));
// GifEncoder.encode(middleCenterWatermarked, new File(outputDir, "middleCenterWatermarked.gif"));
// GifEncoder.encode(middleCenterWatermarked_smoothly, new File(outputDir, "middleCenterWatermarked_smooth.gif"));
// GifEncoder.encode(bottomRightWatermarked, new File(outputDir, "bottomRightWatermarked.gif"));
// GifEncoder.encode(bottomRightWatermarked_smoothly, new File(outputDir, "bottomRightWatermarked_smooth.gif"));
// GifEncoder.encode(coverConsWatermarked, new File(outputDir, "coverConsWatermarked.gif"));
// GifEncoder.encode(coverConsWatermarked_smoothly, new File(outputDir, "coverConsWatermarked_smooth.gif"));
} catch (IOException e) ...{
e.printStackTrace();
}
}
}
/** */ /**
* C-platform All Rights Reserved@2006-2007
* Author: hally
* Date: 2007-2-12
* Time: 19:48:43
* Modifier:hally
* Modify Date&Time: 2007-2-12 19:48:43
*/
import com.gif4j. * ;
import java.awt. * ;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class GifTest ... {
// Usage: java GifImageWatermarkExample [PathToGifImageToWatermark] (please be sure that the gif4j jar is in your CLASSPATH)
// By default the gif4j_logotype.gif as an example gif image is used
public static void main(String[] args) ...{
File gifImageFileToWatermark = null;
if (args.length == 0) ...{
gifImageFileToWatermark = new File("d:/1.gif ");
} else
gifImageFileToWatermark = new File(args[0]);
// load and decode gif image
GifImage gifImage = null;
try ...{
gifImage = GifDecoder.decode(gifImageFileToWatermark);
} catch (IOException e) ...{
e.printStackTrace();
System.exit(1);
}
// change out directory if it is necessary
File outputDir = new File("d:/result");
if (!outputDir.exists())
outputDir.mkdirs();
// create watermark image using TextPainter
TextPainter painter = new TextPainter(new Font("隶书", Font.BOLD, 25));
painter.setOutlinePaint(Color.WHITE);
painter.setForegroundPaint(Color.BLUE);
BufferedImage watermarkImage = painter.renderString("王海利", true);
// create watermark
Watermark watermark = new Watermark(watermarkImage, Watermark.LAYOUT_TOP_LEFT, 0.9f);
// apply watermark
GifImage topLeftWatermarked = watermark.apply(gifImage, true);
// apply watermark smoothly
GifImage topLeftWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
watermark.setLayoutConstraint(Watermark.LAYOUT_MIDDLE_CENTER);
// apply watermark
// GifImage middleCenterWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage middleCenterWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
// watermark.setLayoutConstraint(Watermark.LAYOUT_BOTTOM_RIGHT);
// apply watermark
// GifImage bottomRightWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage bottomRightWatermarked_smoothly = watermark.apply(gifImage, true);
// change the watermark alignment
// watermark.setLayoutConstraint(Watermark.LAYOUT_COVER_CONSECUTIVELY);
// change the watermark transparency
// watermark.setTransparency(0.20f);
// apply watermark
// GifImage coverConsWatermarked = watermark.apply(gifImage, false);
// apply watermark smoothly
// GifImage coverConsWatermarked_smoothly = watermark.apply(gifImage, true);
// Save the results
try ...{
GifEncoder.encode(topLeftWatermarked, new File(outputDir, "topLeftWatermarked.gif"));
GifEncoder.encode(topLeftWatermarked_smoothly, new File(outputDir, "topLeftWatermarked_smooth.gif"));
// GifEncoder.encode(middleCenterWatermarked, new File(outputDir, "middleCenterWatermarked.gif"));
// GifEncoder.encode(middleCenterWatermarked_smoothly, new File(outputDir, "middleCenterWatermarked_smooth.gif"));
// GifEncoder.encode(bottomRightWatermarked, new File(outputDir, "bottomRightWatermarked.gif"));
// GifEncoder.encode(bottomRightWatermarked_smoothly, new File(outputDir, "bottomRightWatermarked_smooth.gif"));
// GifEncoder.encode(coverConsWatermarked, new File(outputDir, "coverConsWatermarked.gif"));
// GifEncoder.encode(coverConsWatermarked_smoothly, new File(outputDir, "coverConsWatermarked_smooth.gif"));
} catch (IOException e) ...{
e.printStackTrace();
}
}
}
需要使用一个jar包,我的网络硬盘上有
http://free5.ys168.com/?hallywang