软件艺术思考者  
混沌,彷徨,立志,蓄势...
公告
日历
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

随笔分类(86)

随笔档案(85)

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

java 图片缩放
import javax.imageio.ImageIO;
import javax.imageio.IIOException;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.io.File;
import java.awt.image.AffineTransformOp;
import java.awt.geom.AffineTransform;

public class ImageTrade2 {

    public static void main (String argv[]) {
        try {
            File fi = new File("C:/001.jpg"); //大图文件
            File fo = new File("C:/002.jpg"); //将要转换出的小图文件
            //if(!fo.exists())fo.createNewFile();
            AffineTransform transform = new AffineTransform();
            BufferedImage bis = ImageIO.read(fi);

            int w = bis.getWidth();
            int h = bis.getHeight();
            double scale = (double)w/h;

            int nw = 120;
            int nh = (nw * h) / w;
            if(nh>120) {
                nh = 120;
                nw = (nh * w) / h;
            }

            double sx = (double)nw / w;
            double sy = (double)nh / h;

            transform.setToScale(sx,sy);

            AffineTransformOp ato = new AffineTransformOp(transform, null);
            BufferedImage bid = new BufferedImage(nw, nh, BufferedImage.TYPE_3BYTE_BGR);
            ato.filter(bis,bid);
            ImageIO.write(bid, "jpeg", fo);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

posted on 2008-07-16 23:23 智者无疆 阅读(460) 评论(1)  编辑  收藏 所属分类: about java
评论:
  • # java 得到当前语种及国际化资源  zlj Posted @ 2008-09-01 17:33
    /**
    * get current language code
    * @param request
    * @return |zh|ja|en|ko|
    * **/
    public static String getCurrentLanguage(HttpServletRequest request){
    String country = request.getLocale().getDisplayLanguage(new Locale("en"));
    String lang = "zh";
    if(country!=null){
    if(country.toLowerCase().contains("ja")){
    lang = "ja";
    }else if(country.toLowerCase().contains("ko")){
    lang = "ko";
    } else if(country.toLowerCase().contains("english")){
    lang = "en";
    }
    }
    return lang;
    }
    /**
    * 国际化
    * @param request
    * @param key
    * @param args:国际化中的参数
    * @param replaceStr:如果找不到相应的key,则用replaceStr做返回值
    * @return
    */
    public static String getResourceValue(HttpServletRequest request,String key,String []args,String replaceStr ){
    //warn:this locle maybe not come from this request,so we can't use request.getLocale(),--by lijun.
    Locale locale = new Locale(WebUtil.getCurrentLanguage(request));
    ResourceBundle resource= ResourceBundle.getBundle("resources.newAdmin", locale);
    //newAdmin_zh.properties位于WEB-INF/classes/resources/文件夹下
    String value=replaceStr;
    try {
    value = resource.getString(key);
    for(int i =0;i<args.length;i++){
    value = value.replace("{"+i+"}", args[i]);
    }
    } catch (RuntimeException e) {
    System.out.print("not find key:"+key);
    }finally{
    return value;
    }

    }  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 智者无疆 Powered by: 博客园 模板提供:沪江博客


   观音菩萨赞