1 7 package java.awt; 8 9 import java.awt.image.ImageProducer ; 10 import java.awt.image.ImageObserver ; 11 import java.awt.image.ImageFilter ; 12 import java.awt.image.FilteredImageSource ; 13 import java.awt.image.AreaAveragingScaleFilter ; 14 import java.awt.image.ReplicateScaleFilter ; 15 16 26 public abstract class Image { 27 28 33 private static ImageCapabilities defaultImageCaps = 34 new ImageCapabilities (false); 35 36 43 protected float accelerationPriority = .5f; 44 45 55 public abstract int getWidth(ImageObserver observer); 56 57 67 public abstract int getHeight(ImageObserver observer); 68 69 77 public abstract ImageProducer getSource(); 78 79 88 public abstract Graphics getGraphics(); 89 90 111 public abstract Object getProperty(String name, ImageObserver observer); 112 113 117 public static final Object UndefinedProperty = new Object (); 118 119 149 public Image getScaledInstance(int width, int height, int hints) { 150 ImageFilter filter; 151 if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) { 152 filter = new AreaAveragingScaleFilter (width, height); 153 } else { 154 filter = new ReplicateScaleFilter (width, height); 155 } 156 ImageProducer prod; 157 prod = new FilteredImageSource (getSource(), filter); 158 return Toolkit.getDefaultToolkit().createImage(prod); 159 } 160 161 165 public static final int SCALE_DEFAULT = 1; 166 167 172 public static final int SCALE_FAST = 2; 173 174 179 public static final int SCALE_SMOOTH = 4; 180 181 190 public static final int SCALE_REPLICATE = 8; 191 192 200 public static final int SCALE_AREA_AVERAGING = 16; 201 202 218 public abstract void flush(); 219 220 242 public ImageCapabilities getCapabilities(GraphicsConfiguration gc) { 243 return defaultImageCaps; 248 } 249 250 270 public void setAccelerationPriority(float priority) { 271 if (priority < 0 || priority > 1) { 272 throw new IllegalArgumentException ("Priority must be a value " + 273 "between 0 and 1, inclusive"); 274 } 275 accelerationPriority = priority; 276 } 277 278 285 public float getAccelerationPriority() { 286 return accelerationPriority; 287 } 288 } 289 | Popular Tags |