< prev index next >

src/java.desktop/share/classes/java/awt/image/CropImageFilter.java

Print this page




  48     int cropY;
  49     int cropW;
  50     int cropH;
  51 
  52     /**
  53      * Constructs a CropImageFilter that extracts the absolute rectangular
  54      * region of pixels from its source Image as specified by the x, y,
  55      * w, and h parameters.
  56      * @param x the x location of the top of the rectangle to be extracted
  57      * @param y the y location of the top of the rectangle to be extracted
  58      * @param w the width of the rectangle to be extracted
  59      * @param h the height of the rectangle to be extracted
  60      */
  61     public CropImageFilter(int x, int y, int w, int h) {
  62         cropX = x;
  63         cropY = y;
  64         cropW = w;
  65         cropH = h;
  66     }
  67 











  68     /**
  69      * Passes along  the properties from the source object after adding a
  70      * property indicating the cropped region.
  71      * This method invokes {@code super.setProperties},
  72      * which might result in additional properties being added.
  73      * <p>
  74      * Note: This method is intended to be called by the
  75      * {@code ImageProducer} of the {@code Image} whose pixels
  76      * are being filtered. Developers using
  77      * this class to filter pixels from an image should avoid calling
  78      * this method directly since that operation could interfere
  79      * with the filtering operation.
  80      */
  81     public void setProperties(Hashtable<?,?> props) {
  82         @SuppressWarnings("unchecked")
  83         Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
  84         p.put("croprect", new Rectangle(cropX, cropY, cropW, cropH));
  85         super.setProperties(p);
  86     }
  87 




  48     int cropY;
  49     int cropW;
  50     int cropH;
  51 
  52     /**
  53      * Constructs a CropImageFilter that extracts the absolute rectangular
  54      * region of pixels from its source Image as specified by the x, y,
  55      * w, and h parameters.
  56      * @param x the x location of the top of the rectangle to be extracted
  57      * @param y the y location of the top of the rectangle to be extracted
  58      * @param w the width of the rectangle to be extracted
  59      * @param h the height of the rectangle to be extracted
  60      */
  61     public CropImageFilter(int x, int y, int w, int h) {
  62         cropX = x;
  63         cropY = y;
  64         cropW = w;
  65         cropH = h;
  66     }
  67 
  68     @Override
  69     public ImageFilter getScaledFilterInstance(double scaleX, double scaleY) {
  70         Object instance = super.getScaledFilterInstance(scaleX, scaleY);
  71         CropImageFilter filter = (CropImageFilter) instance;
  72         filter.cropX = (int) Math.ceil(cropX * scaleX);
  73         filter.cropY = (int) Math.ceil(cropY * scaleY);
  74         filter.cropW = (int) Math.floor(cropW * scaleX);
  75         filter.cropH = (int) Math.floor(cropH * scaleY);
  76         return filter;
  77     }
  78 
  79     /**
  80      * Passes along  the properties from the source object after adding a
  81      * property indicating the cropped region.
  82      * This method invokes {@code super.setProperties},
  83      * which might result in additional properties being added.
  84      * <p>
  85      * Note: This method is intended to be called by the
  86      * {@code ImageProducer} of the {@code Image} whose pixels
  87      * are being filtered. Developers using
  88      * this class to filter pixels from an image should avoid calling
  89      * this method directly since that operation could interfere
  90      * with the filtering operation.
  91      */
  92     public void setProperties(Hashtable<?,?> props) {
  93         @SuppressWarnings("unchecked")
  94         Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
  95         p.put("croprect", new Rectangle(cropX, cropY, cropW, cropH));
  96         super.setProperties(p);
  97     }
  98 


< prev index next >