Package java.awt.image

Examples of java.awt.image.AffineTransformOp


                h = (int) Math.round(w * d);
            }

            AffineTransform xform = AffineTransform.getScaleInstance((double) h
                    / (double) fullH, (double) w / (double) fullW);
            AffineTransformOp op = new AffineTransformOp(xform,
                    AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            BufferedImage newImage = new BufferedImage(w, h,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D gr = newImage.createGraphics();
            int top = 0;
View Full Code Here


            h = (int) Math.round(w * d);
        }

        AffineTransform xform = AffineTransform.getScaleInstance((double) h
                / (double) fullH, (double) w / (double) fullW);
        AffineTransformOp op = new AffineTransformOp(xform,
                AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        BufferedImage newImage = new BufferedImage(this.thumbW, this.thumbH,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D gr = newImage.createGraphics();
        gr.setColor(Color.BLACK);
View Full Code Here

                if (width > 0 || height > 0) {
                    JPEGDecodeParam decodeParam = decoder.getJPEGDecodeParam();
                    double ow = decodeParam.getWidth();
                    double oh = decodeParam.getHeight();

                    AffineTransformOp filter = new AffineTransformOp(getTransform(ow, oh, width, height), AffineTransformOp.TYPE_BILINEAR);
                    WritableRaster scaledRaster = filter.createCompatibleDestRaster(currentImage.getRaster());

                    filter.filter(currentImage.getRaster(), scaledRaster);

                    currentImage = new BufferedImage(original.getColorModel(), scaledRaster, true, null);
                }

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

    int pixX = (int)((double) this.getWidth() / scale);
    int pixY = (int)((double) this.getHeight() / scale);
    // log.debug("Max image size on screen ("+this.getWidth()+"/"+this.getHeight()+") with current zoom: "+pixX+"/"+pixY);

    if(pixX>mapImage.getWidth() && pixY>mapImage.getHeight()) {
      g2d.drawImage (mapImage, new AffineTransformOp(at, null), 0, 0);
    }
    else if(pixX>mapImage.getWidth()) {
      g2d.drawImage (mapImage.getSubimage(0, offset.y, mapImage.getWidth(), pixY), new AffineTransformOp(at, null), 0, 0);
    }
    else if(pixY>mapImage.getHeight()) {
      g2d.drawImage (mapImage.getSubimage(offset.x, 0, pixX, mapImage.getHeight()), new AffineTransformOp(at, null), 0, 0);
    }
    else {
      int maxX = pixX;
      int maxY = pixY;
      if(mapImage.getWidth()<maxX) maxX = mapImage.getWidth()-1;
      if(mapImage.getHeight()<maxY) maxY = mapImage.getHeight()-1;
      g2d.drawImage (mapImage.getSubimage(offset.x, offset.y, maxX, maxY), new AffineTransformOp(at, null), 0, 0);
    }
   
    g2d.dispose();
    // log.debug("mapPanel: "+(System.currentTimeMillis()-ts)+"ms");
View Full Code Here

        xs = ys;
      }
      System.out.println("scale factor: "+xs+"/"+ys);
      at = AffineTransform.getScaleInstance(xs, ys);
      Graphics2D g2 = (Graphics2D)g;       
      g2.drawImage(mapImage, new AffineTransformOp(at, null), 0, 0);
    }
    else {
      g2d.drawImage (mapImage.getSubimage(offset.x, offset.y, this.getWidth(), this.getHeight()), null, 0, 0);
    }
   
View Full Code Here

                JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(inputStream);
                Raster original = decoder.decodeAsRaster();
                JPEGDecodeParam decodeParam = decoder.getJPEGDecodeParam();
                double ow = decodeParam.getWidth();
                double oh = decodeParam.getHeight();
                AffineTransformOp filter = new AffineTransformOp(getTransform(ow, oh, width, height), AffineTransformOp.TYPE_BILINEAR);
                WritableRaster scaled = filter.createCompatibleDestRaster(original);
                filter.filter(original, scaled);

                if (!handleJVMBug()) {
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug( "No need to handle JVM bug" );
                    }
View Full Code Here

        // Translate what will be at minX,minY to zero, zero
        // which where java2d will think the real minX,minY is.
        aff.preConcatenate(AffineTransform.getTranslateInstance
                           (-destPt.getX(), -destPt.getY()));

        AffineTransformOp op = new AffineTransformOp(aff, hints);

        BufferedImage srcBI, myBI;
        ColorModel srcCM = src.getColorModel();
        ColorModel myCM = getColorModel();

        WritableRaster srcWR = (WritableRaster)srcRas;
        // If the output buffer is not premultiplied in certain cases
        // it fails to properly divide out the Alpha (it always does
        // the affine on premultiplied data). We help it out by
        // premultiplying for it.
        srcCM = GraphicsUtil.coerceData(srcWR, srcCM, true);
        srcBI = new BufferedImage(srcCM,
                                  srcWR.createWritableTranslatedChild(0,0),
                                  srcCM.isAlphaPremultiplied(), null);

        myBI = new BufferedImage(myCM,wr.createWritableTranslatedChild(0,0),
                                 myCM.isAlphaPremultiplied(), null);

        op.filter(srcBI, myBI);

        // if ((count % 40) == 0) {
        //     org.apache.batik.ImageDisplay.showImage("Src: " , srcBI);
        //     org.apache.batik.ImageDisplay.showImage("Dst: " , myBI);
        // }
View Full Code Here

    double scaleX = (double) width / source.getWidth();
    double scaleY = (double) height / source.getHeight();
    AffineTransform scaleTransform = AffineTransform.getScaleInstance(
        scaleX, scaleY);
    AffineTransformOp bilinearScaleOp = new AffineTransformOp(
        scaleTransform, AffineTransformOp.TYPE_BILINEAR);

    return bilinearScaleOp.filter(source, new BufferedImage(width, height,
        source.getType()));
  }
View Full Code Here

    if ( scaleX > 0 && scaleY > 0 )
      transform.scale(scaleX, scaleY);
    if ( shearX > 0 && shearY > 0 )
      transform.shear(shearX, shearY);
   
    AffineTransformOp op = new AffineTransformOp(transform,AffineTransformOp.TYPE_BILINEAR);
    BufferedImage dest = new BufferedImage(image.getWidth(),image.getHeight(),image.getType());
    op.filter(image, dest);
    return dest;
  }
View Full Code Here

        double xScale;
        double yScale;

        AffineTransform transform;
        AffineTransformOp scale;

        if (type > AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
            // Initially scale so all remaining operations will halve the image
            if ((width < input.getWidth()) || (height < input.getHeight())) {
                int w = width;
                int h = height;
                while (w < (input.getWidth() / 2)) {
                    w *= 2;
                }
                while (h < (input.getHeight() / 2)) {
                    h *= 2;
                }

                xScale = w / (double)input.getWidth();
                yScale = h / (double)input.getHeight();

                //System.out.println("First scale by x=" + xScale + ", y=" + yScale);

                transform = AffineTransform.getScaleInstance(xScale, yScale);
                scale = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
                temp = scale.filter(temp, null);
            }
        }

        scale = null; // NOTE: This resets!

        xScale = width / (double)temp.getWidth();
        yScale = height / (double)temp.getHeight();

        if (type > AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
            // TODO: Test skipping first scale (above), and instead scale once
            // more here, and a little less than .5 each time...
            // That would probably make the scaling smoother...
            while ((xScale < 0.5) || (yScale < 0.5)) {
                if (xScale >= 0.5) {
                    //System.out.println("Halving by y=" + (yScale * 2.0));
                    transform = AffineTransform.getScaleInstance(1.0, 0.5);
                    scale = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);

                    yScale *= 2.0;
                } else if (yScale >= 0.5) {
                    //System.out.println("Halving by x=" + (xScale * 2.0));
                    transform = AffineTransform.getScaleInstance(0.5, 1.0);
                    scale = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);

                    xScale *= 2.0;
                } else {
                    //System.out.println("Halving by x=" + (xScale * 2.0)  + ", y=" + (yScale * 2.0));
                    xScale *= 2.0;
                    yScale *= 2.0;
                }

                if (scale == null) {
                    transform = AffineTransform.getScaleInstance(0.5, 0.5);
                    scale = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
                }

                temp = scale.filter(temp, null);
            }
        }

        //System.out.println("Rest to scale by x=" + xScale + ", y=" + yScale);

        transform = AffineTransform.getScaleInstance(xScale, yScale);
        scale = new AffineTransformOp(transform, type);

        return scale.filter(temp, output);
    }
View Full Code Here

TOP

Related Classes of java.awt.image.AffineTransformOp

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.