< prev index next >
src/java.desktop/share/classes/sun/awt/image/BufferedImageGraphicsConfig.java
Print this page
@@ -43,42 +43,65 @@
public class BufferedImageGraphicsConfig
extends GraphicsConfiguration
{
private static final int numconfigs = BufferedImage.TYPE_BYTE_BINARY;
- private static BufferedImageGraphicsConfig configs[] =
+ private static BufferedImageGraphicsConfig standardConfigs[] =
+ new BufferedImageGraphicsConfig[numconfigs];
+ private static BufferedImageGraphicsConfig scaledConfigs[] =
new BufferedImageGraphicsConfig[numconfigs];
public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg) {
+ return getConfig(bImg, 1, 1);
+ }
+
+ public static BufferedImageGraphicsConfig getConfig(BufferedImage bImg,
+ double scaleX,
+ double scaleY)
+ {
BufferedImageGraphicsConfig ret;
int type = bImg.getType();
+
+ BufferedImageGraphicsConfig[] configs = (scaleX == 1 && scaleY == 1)
+ ? standardConfigs : scaledConfigs;
+
if (type > 0 && type < numconfigs) {
ret = configs[type];
- if (ret != null) {
+ if (ret != null && ret.scaleX == scaleX && ret.scaleY == scaleY) {
return ret;
}
}
- ret = new BufferedImageGraphicsConfig(bImg, null);
+ ret = new BufferedImageGraphicsConfig(bImg, null, scaleX, scaleY);
if (type > 0 && type < numconfigs) {
configs[type] = ret;
}
return ret;
}
GraphicsDevice gd;
ColorModel model;
Raster raster;
+ private final double scaleX;
+ private final double scaleY;
public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp) {
+ this(bufImg, comp, 1, 1);
+ }
+
+ public BufferedImageGraphicsConfig(BufferedImage bufImg, Component comp,
+ double scaleX, double scaleY)
+ {
if (comp == null) {
this.gd = new BufferedImageDevice(this);
} else {
Graphics2D g2d = (Graphics2D)comp.getGraphics();
this.gd = g2d.getDeviceConfiguration().getDevice();
}
this.model = bufImg.getColorModel();
this.raster = bufImg.getRaster().createCompatibleWritableRaster(1, 1);
+ this.scaleX = scaleX;
+ this.scaleY = scaleY;
}
/**
* Return the graphics device associated with this configuration.
*/
@@ -136,11 +159,11 @@
* the device, with X coordinates
* increasing to the right and Y coordinates increasing downwards.
* For image buffers, this Transform will be the Identity transform.
*/
public AffineTransform getDefaultTransform() {
- return new AffineTransform();
+ return AffineTransform.getScaleInstance(scaleX, scaleY);
}
/**
*
* Returns a Transform that can be composed with the default Transform
< prev index next >