-imagemagick+jmagick of the Java Image Processing tool (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.