关闭

开源之美!java-image-scaling

标签: nullfilterimagefloatclassjava
2355人阅读 评论(0) 收藏 举报
分类:

项目主页:http://code.google.com/p/java-image-scaling/

Getting Started!

Introduction

This will guide you through how to rescale images using this library.

A simple rescale

Lets say that you have a BufferedImage instance called tomato that should be rescaled to 100x200. If you want a high quality rescale, you should choose the ResampleOp class:

ResampleOp  resampleOp = new ResampleOp (100,200);
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

Tip: You might need to increase your maximum heap. This can be done using the -Xmx parameter, such as: java -Xmx512m MyJavaClass

Using Unsharpen Filter

Let's improve the quality a bit more adding a unsharpen filter to the final image. This will remove some of blur, that a rescale operation creates.

ResampleOp  resampleOp = new ResampleOp (100,200);
resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

Adding a listener

If your tomato image was very large, this might take some time. The following code add a change listener so the user can see that the computer is actually is working.

ResampleOp  resampleOp = new ResampleOp (100,200);
resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal);
resampleOp.addProgressListener(new ProgressListener() {
  public void notifyProgress(float fraction) {
    System.out.printf("Still working - %f percent %n",fraction*100);
  }
});
BufferedImage rescaledTomato = resampleOp.filter(tomato, null);

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2149012次
    • 积分:23176
    • 等级:
    • 排名:第302名
    • 原创:232篇
    • 转载:740篇
    • 译文:1篇
    • 评论:188条
    最新评论