View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-9-26 上午10:26:16
4    */
5   package gboat2.attachment.watermark;
6   
7   /**
8    * 策略工厂类 
9    * @author tanxw
10   * @since jdk1.6
11   * @date 2012-9-26
12   *  
13   */
14  
15  public abstract class WatermarkFactory {
16  	
17  	/**
18  	 * 打水印,尽最大努力调用多种策略使得水印打成功
19  	 * @param srcImg
20  	 * @param targetImg
21  	 * @param watermarkImg
22  	 * @throws Exception
23  	 */
24  	public static void watermark(String srcImg, String targetImg, String watermarkImg) throws Exception {
25  		WatermarkStrategy strategy = new IM4JavaWatermarkStrategy();
26  		try {
27  			strategy.watermark(srcImg, targetImg, watermarkImg);
28  		} catch (Throwable e) {//必须捕获Throwable类型,下层有可能抛出Error
29  			strategy = new JMagickWatermarkStrategy();
30  			strategy.watermark(srcImg, targetImg, watermarkImg);
31  		}
32  	}
33  	
34  }