Simple picture processing test class:
public class Imageutil {
static{
system.setproperty ("Jmagick.systemclassloader", "no"); Have to
}
/**
* Compress Pictures
*/
public void CreateImage (String filepath,string topath, int width, int height) {
Imageinfo info = null; Loading pictures
Magickimage image = null;
Magickimage scaled = null;
Dimension Dim=null;
try {
info = new Imageinfo (filepath);
Image = new Magickimage (info);
Dim = Image.getdimension ();
Double w = dim.getwidth ();
Double h = dim.getheight ();
int toheight = (int) (h*width/w);//scale by width
scaled = image.scaleimage (width, toheight);//small picture file size.
Scaled.setfilename (topath+width+height+ ". jpg"); Set picture name, must have save picture path
Scaled.writeimage (info);
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (image!=null)
{
Image.destroyimages ();
}
if (scaled! = null) {
Scaled.destroyimages ();
}
}
}
public static void Main (string[] args) {
String filepath= "D:/xxxx.jpg";
String topath= "d:/xxxxx/";
int width=400;
int height=553;
Imageutil image=new imageutil ();
Image.createimage (filepath, topath, width, height);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
-imagemagick+jmagick of the Java Image Processing tool (ii)