Example usage for java.awt.image RescaleOp filter

List of usage examples for java.awt.image RescaleOp filter

Introduction

In this page you can find the example usage for java.awt.image RescaleOp filter.

Prototype

public final WritableRaster filter(Raster src, WritableRaster dst) 

Source Link

Document

Rescales the pixel data in the source Raster.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    BufferedImage bufferedImage = new BufferedImage(200, 200, BufferedImage.TYPE_BYTE_INDEXED);

    float scaleFactor = 1.3f;
    RescaleOp op = new RescaleOp(scaleFactor, 0, null);
    bufferedImage = op.filter(bufferedImage, null);

}

From source file:ImageOps.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    int w = getSize().width;
    int h = getSize().height;

    g2.setColor(Color.black);/*from   w w w . ja  v  a 2  s  . co  m*/
    float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter
            0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 };

    String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" };
    for (int i = 0; i < bi.length; i++) {
        int iw = bi[i].getWidth(this);
        int ih = bi[i].getHeight(this);
        int x = 0, y = 0;

        AffineTransform at = new AffineTransform();
        at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih);

        BufferedImageOp biop = null;
        BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);

        switch (i) {
        case 0:
        case 1:
            x = i == 0 ? 5 : w / 2 + 3;
            y = 15;
            Kernel kernel = new Kernel(3, 3, data[i]);
            ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
            cop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            break;
        case 2:
            x = 5;
            y = h / 2 + 15;
            byte chlut[] = new byte[256];
            for (int j = 0; j < 200; j++)
                chlut[j] = (byte) (256 - j);
            ByteLookupTable blut = new ByteLookupTable(0, chlut);
            LookupOp lop = new LookupOp(blut, null);
            lop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
            break;
        case 3:
            x = w / 2 + 3;
            y = h / 2 + 15;
            RescaleOp rop = new RescaleOp(1.1f, 20.0f, null);
            rop.filter(bi[i], bimg);
            biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
        }
        g2.drawImage(bimg, biop, x, y);
        TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, (float) x, (float) y - 4);
    }
}

From source file:org.iish.visualmets.services.ImageTransformation.java

public BufferedImage ContrastBrightnessImage(BufferedImage img, float contrast, float brightness) {
    // BRIGHTNESS / CONTRAST
    // scale factor (contrast) (bv. 0 - zwart, 1 - default, 5 - heel licht)
    // offset (brightness) (bv. -100, -90, ..., -20, -10, 0, 10, 20, 90, 100)

    if (contrast != 1f || brightness != 0f) {
        RescaleOp rescaleOp = new RescaleOp(contrast, brightness, null);
        rescaleOp.filter(img, img);
    }/*from   ww  w.  j  a  v  a2s  . c  o  m*/

    return img;
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jSliderBrilloStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSliderBrilloStateChanged
    VentanaInterna vi = (VentanaInterna) (escritorio.getSelectedFrame());

    if (vi != null) {
        BufferedImage ImgSource = vi.getLienzo().getImage();
        if (img == null)
            img = ImgSource;/*from www . j av  a  2s  . com*/
        if (ImgSource != null) {
            try {
                float slider = jSliderBrillo.getValue();
                RescaleOp rop = new RescaleOp(1.0F, slider, null);
                BufferedImage imgdest = rop.filter(this.img, null);
                vi.getLienzo().setImage(imgdest);
                vi.getLienzo().repaint();

            } catch (IllegalArgumentException e) {
                System.err.println(e.getLocalizedMessage());
            }
        }
    }
}