Use Image.getScaledInstance() in resize method and immediately set new width and height. Some reformatting.

This commit is contained in:
hns 2002-10-02 09:32:09 +00:00
parent bd1d880506
commit 90efca76fa

View file

@ -1,6 +1,6 @@
// ImageWrapper.java // ImageWrapper.java
// Copyright (c) Hannes Wallnöfer 1999-2000 // Copyright (c) Hannes Wallnöfer 1999-2000
package helma.image; package helma.image;
import java.awt.*; import java.awt.*;
@ -42,9 +42,9 @@ public abstract class ImageWrapper {
*/ */
public void setFont (String name, int style, int size) { public void setFont (String name, int style, int size) {
this.fontname = name; this.fontname = name;
this.fontstyle = style; this.fontstyle = style;
this.fontsize = size; this.fontsize = size;
g.setFont (new Font (name, style, size)); g.setFont (new Font (name, style, size));
} }
@ -94,8 +94,11 @@ public abstract class ImageWrapper {
} }
public void resize (int w, int h) { public void resize (int w, int h) {
ImageFilter filter = new AreaAveragingScaleFilter (w, h); // ImageFilter filter = new ReplicateScaleFilter (w, h);
img = Toolkit.getDefaultToolkit ().createImage(new FilteredImageSource(img.getSource(), filter)); // img = Toolkit.getDefaultToolkit ().createImage(new FilteredImageSource(img.getSource(), filter));
img = img.getScaledInstance (w, h, Image.SCALE_SMOOTH);
width = w;
height = h;
} }
public abstract void reduceColors (int colors); public abstract void reduceColors (int colors);
@ -221,7 +224,7 @@ public abstract class ImageWrapper {
} }
public void paint (Graphics g, int xadd, int yadd) { public void paint (Graphics g, int xadd, int yadd) {
g.drawString (text, xoff+xadd, yoff+ascent+yadd); g.drawString (text, xoff+xadd, yoff+ascent+yadd);
} }
@ -229,7 +232,7 @@ public abstract class ImageWrapper {
return (y < yoff+fm.getHeight()) ? true : false; return (y < yoff+fm.getHeight()) ? true : false;
} }
} }
} }