Package java.awt.image

Examples of java.awt.image.RescaleOp


        //this defines opacity
        float[] scales = { 1f, 1f, 1f, 1f};
        scales[3] = layerImage.getOpacity() / 100f;
        //System.out.println(scales[3]);
        float[] offsets = new float[4];
        RescaleOp rop = new RescaleOp(scales, offsets, null);
        logger.info("drawing layer...");
    compositeImageGraphicsObj.drawImage(currentImg, rop, 0, 0);
    //cleaning up temp file
    imgFile.delete();
  }
View Full Code Here


            Graphics2D g = (Graphics2D) iconImage.getGraphics();
            icon.paintIcon(this, g, 0, 0);
            g.dispose();

            float scale = 0.5f;
            RescaleOp rop = new RescaleOp(new float[]{scale, scale, scale, scale},
                                new float[]{0, 0, 0, 0},
                                null);
            BufferedImage image = rop.filter(iconImage, null);

            this.setDisabledIcon(new ImageIcon(image));

            super.setText(null);
        }
View Full Code Here

            Graphics2D g = (Graphics2D) iconImage.getGraphics();
            icon.paintIcon(null, g, 0, 0);
            g.dispose();

            float scale = 0.5f;
            RescaleOp rop = new RescaleOp(new float[]{scale, scale, scale, scale},
                                new float[]{0, 0, 0, 0},
                                null);
            BufferedImage image = rop.filter(iconImage, null);

            this.setDisabledIcon(new ImageIcon(image));
        }

        if (icon != null) {
View Full Code Here

     *            The graphics to draw on
     */
    private void draw(final Graphics2D graphics)
    {
      final float[] offsets = new float[4];
      final RescaleOp rop = new RescaleOp(scales, offsets, null);
      if (isHighlighted)
      {
        graphics.drawImage(getAnimal().highlightedImage, rop, location.x, location.y);
      }
      else
View Full Code Here

     *            The graphics to draw on
     */
    private void draw(final Graphics2D graphics)
    {
      final float[] offsets = new float[4];
      final RescaleOp rop = new RescaleOp(scales, offsets, null);
      if (isHighlighted)
      {
        graphics.drawImage(getAnimal().highlightedImage, rop, location.x, location.y);
      }
      else
View Full Code Here

    // Create an image to work on
    BufferedImage img = new BufferedImage(20, 20, BufferedImage.TYPE_USHORT_GRAY);
    WritableRaster r = img.getRaster();
    r.setSample(1, 1, 0, 150);
   
    RescaleOp op = new RescaleOp(1, 1, null);
   
    // Src and dst rasters can be the same
    try
    {
      op.filter(r, r);
      harness.check(true);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(false);
    }
   
    // Src and dst are different sizes (not allowed, unlike some other Ops)
    BufferedImage dst = new BufferedImage(30, 40, BufferedImage.TYPE_INT_RGB);
    try
    {
      op.filter(r, dst.getRaster());
      harness.check(false);
    }
    catch (IllegalArgumentException e)
    {
      harness.check(true);
    }
   
    // Null destination check
    WritableRaster dstRast = op.filter(r, null);
    harness.check(dstRast.getHeight(), r.getHeight());
    harness.check(dstRast.getWidth(), r.getWidth());
    harness.check(dstRast.getMinX(), r.getMinX());
    harness.check(dstRast.getMinY(), r.getMinY());
    harness.check(dstRast.getNumBands(), r.getNumBands());
    harness.check(dstRast.getNumDataElements(), r.getNumDataElements());
    harness.check(dstRast.getTransferType(), r.getTransferType());
    harness.check(dstRast.getBounds(), r.getBounds());
    harness.check(dstRast.getDataBuffer().getClass(), r.getDataBuffer().getClass());
   
    // Test positive & negative clipping behaviour
    img.getRaster().setSample(1, 1, 0, 1500);
    op = new RescaleOp(100, 0, null);
    dstRast = op.filter(r, null);
    double maxValue = Math.pow(2, r.getSampleModel().getSampleSize(0)) - 1;
    harness.check(dstRast.getSample(1, 1, 0), maxValue);
   
    op = new RescaleOp(1, -2000, null);
    dstRast = op.filter(r, null);
    harness.check(dstRast.getSample(1, 1, 0), 0);
  }
View Full Code Here

    r.setSample(1, 3, 0, 45);
    r.setSample(1, 3, 1, 60);
    r.setSample(1, 3, 2, 70);
    r.setSample(1, 3, 3, 90);
   
    RescaleOp op = new RescaleOp(0.75f, 25f, null);
    WritableRaster dest = op.filter(r, null);
   
    harness.check(dest.getSample(1, 1, 0), 137);    //rounded down from 137.5
    harness.check(dest.getSample(1, 1, 1), 145);
    harness.check(dest.getSample(1, 1, 3), 171);    //rounded down from 171.25
    harness.check(dest.getSample(1, 1, 2), 156);    //rounded down from 156.25
View Full Code Here

    r.setSample(1, 3, 0, 45);
    r.setSample(1, 3, 1, 60);
    r.setSample(1, 3, 2, 70);
    r.setSample(1, 3, 3, 90);
   
    RescaleOp op = new RescaleOp(new float[]{0.75f, 2.5f, -1f, 0f},
                             new float[]{25f, 2f, 1f, 0f},
                             null);
    WritableRaster dest = op.filter(r, null);
   
    harness.check(dest.getSample(1, 1, 0), 32);     //rounded down from 32.5
    harness.check(dest.getSample(1, 1, 1), 52);
    harness.check(dest.getSample(1, 1, 2), 0);
    harness.check(dest.getSample(1, 1, 3), 0);
View Full Code Here

    r.setSample(1, 3, 1, 60);
    r.setSample(1, 3, 2, 70);
    r.setSample(1, 3, 3, 90);

    // Test mismatched arrays
    RescaleOp op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1, 2, 3}, null);
    try
    {
      op.filter(r, null);
      harness.check(false);
    }
    catch (IllegalArgumentException ex)
    {
      harness.check(true);
    }
   
    // Only the first value from both arrays is read if the offsets array
    // has only one value
    op = new RescaleOp(new float[]{1, 2, 3, 4}, new float[]{1}, null);
    try
    {
      WritableRaster dest = op.filter(r, null);
      harness.check(dest.getSample(1, 1, 0), 11);
      harness.check(dest.getSample(1, 1, 1), 21);
      harness.check(dest.getSample(1, 3, 0), 46);
      harness.check(dest.getSample(1, 3, 1), 61);
    }
    catch (IllegalArgumentException ex)
    {
      harness.check(false);
    }
   
    // Same with a single-length factors array
    op = new RescaleOp(new float[]{0.5f}, new float[]{2, 3, 4, 5}, null);
    try
    {
      WritableRaster dest = op.filter(r, null);
      harness.check(dest.getSample(1, 1, 0), 7);
      harness.check(dest.getSample(1, 1, 1), 12);
      harness.check(dest.getSample(1, 3, 0), 24);
      harness.check(dest.getSample(1, 3, 1), 32);
    }
View Full Code Here

   *
   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    RescaleOp op = new RescaleOp(1, 1, null);
    Raster raster = Raster.createWritableRaster(
        new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 8), null);
    Raster dest = op.createCompatibleDestRaster(raster);
    harness.check(dest.getWidth(), 10);
    harness.check(dest.getHeight(), 20);
    harness.check(dest.getNumBands(), 1);
    harness.check(dest.getSampleModel() instanceof MultiPixelPackedSampleModel);
    harness.check(dest.getTransferType(), raster.getTransferType());
    harness.check(dest.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
    harness.check(dest.getNumDataElements(), raster.getNumDataElements());
 
    // try null argument
    boolean pass = false;
    try
    {
      op.createCompatibleDestRaster(null);
    }
    catch (NullPointerException e)
    {
      pass = true;
    }
    harness.check(pass);
   
    // Try a different type
    raster = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, 25, 40, 3, new Point(5, 5));
    Raster dst = op.createCompatibleDestRaster(raster);
    harness.check(dst.getNumBands(), raster.getNumBands());
    harness.check(dst.getTransferType(), raster.getTransferType());
    harness.check(dst.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
    harness.check(dst.getNumDataElements(), raster.getNumDataElements());
   
    // Try a different number of bands
    raster = Raster.createBandedRaster(DataBuffer.TYPE_INT, 25, 40, 5, new Point(5, 5));
    dst = op.createCompatibleDestRaster(raster);
    harness.check(dst.getNumBands(), raster.getNumBands());
    harness.check(dst.getTransferType(), raster.getTransferType());
    harness.check(dst.getDataBuffer().getDataType(), raster.getDataBuffer().getDataType());
    harness.check(dst.getNumDataElements(), raster.getNumDataElements());
  }
View Full Code Here

TOP

Related Classes of java.awt.image.RescaleOp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.