Linux平台下对JMagick的一个简单封装(3)

} finally {
   if (cropped != null) {
    cropped.destroyImages();
   }
  }
 }
 
 /**删除图片文件
  * @param src  图片位置
  * @return
  * @throw
  * @author sulliy@sina.com 2010-8-11
  */
 public static boolean removeFile(String src) throws SecurityException{
  try {
   if (!checkType(src)) {
    return false;
   }
   
   File file = new File(src);
   return file.delete();  
  } catch (Exception e) {
   e.printStackTrace();
   return false;
  }
 }
}

可以写个简单的测试

import java.awt.Point;

import magick.MagickException;


public class JMagicjWrapperTest {
 public static void main(String[] args) throws MagickException{
  
  //test for function imageResize
  
  JMagicjWrapper.imageResize("pics.jpg", "reSize20x30.png", 20, 30);
  JMagicjWrapper.imageResize("pics.jpg", "reSize250x200.jpeg", 250, 200);
  JMagicjWrapper.imageResize("pics.jpg", "reSize50x50.jpg", 50, 50);
  JMagicjWrapper.imageResize("pics.jpg", "reSize120x120.bmp", 120, 120);
  JMagicjWrapper.imageResize("pics.jpg", "reSize.tif", 20, 30);//not create file
  
  
  //test for function createWaterPrintByImg
  JMagicjWrapper.createWaterPrintByImg("pics.jpg", "wpl.gif", "logo.jpg", new Point(100,100));
  JMagicjWrapper.imageResize("wpl.gif", "logo250x200.gif", 250, 200);
  //Because file "wpl.gif" may not be release, the later function cause a error, can not open file handle.
  //JMagicjWrapper.createWaterPrintByImg("pics.jpg", "wpl.gif", "logoFull.jpg", new Point(1680,1050));//not create file
  //JMagicjWrapper.createWaterPrintByImg("pics.jpg", "wpl.gif", "logoExt.jpg", new Point(2000,1000));//not create file
  
  //test for function createWaterPrintByText
  //This function can not handle Chinese Character, I'll continue to takle the issue
  JMagicjWrapper.createWaterPrintByText("pics1.jpg", "wpt.gif", "For Test", new Point(300,300), 100);
 }
}

运行可能会报无法获得文件句柄的错误,请仔细检查图片的路径。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwpyzy.html