Popular Posts
Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... CTE, recursive search WITH DepartmentSearch(DeptID, DeptParent, DeptName, OuID) AS (     -- 找出簽核者所屬部門     SELECT d.DeptID, d.DeptParent, d.DeptName, d.OuID     FR... Create web service client cross SSL with eclipse When creating web service cross SSL using eclipse, it occuss some error like below: And it can't build the client source from this wa...
Blog Archive
Stats
Resize image using Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apptraining;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author BruceTsai
 */
public class ImageResizer {

    public static void doit(String soureFile, String targetFile, double percentage) throws IOException {
        BufferedImage image = ImageIO.read(new File(soureFile));
        System.out.println(String.format("原始檔寬度 : %d , 原始檔高度 : %d", image.getWidth(), image.getHeight()));
        int[] size = new int[]{(int) (image.getWidth() * percentage), (int) (image.getHeight() * percentage)};
        System.out.println(String.format("轉換後寬度 : %d , 轉換後高度 : %d", size[0], size[1]));
        BufferedImage target = new BufferedImage(size[0], size[1], image.getType());
        Graphics2D graphic = target.createGraphics();
        graphic.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphic.drawImage(image, 0, 0, size[0], size[1], null);
        ImageIO.write(target, "jpg", new File(targetFile));
    }
}