Package java.awt.image

Examples of java.awt.image.AffineTransformOp


                }

                // We flip our image because .ICO and .CUR will always be reversed.
                AffineTransform trans = AffineTransform.getScaleInstance(1, -1);
                trans.translate(0, -img.getHeight(null));
                AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR);
                img = op.filter(img, null);

                singleCursor = BufferUtils.createIntBuffer(img.getWidth() * img.getHeight());
                DataBufferInt dataIntBuf = (DataBufferInt) img.getData().getDataBuffer();
                singleCursor = IntBuffer.wrap(dataIntBuf.getData());
                cursors.add(singleCursor);
View Full Code Here


        BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);

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

        BufferedImage scaledImage = bilinearScaleOp.filter(sourceImage, new BufferedImage(width, height, sourceImage.getType()));
        return ImageUtils.toJmeImage(scaledImage, source.getFormat());
    }
View Full Code Here

     * @return The flipped image
     */
    public static Image flipImage(BufferedImage image) {
        AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
        tx.translate(-image.getWidth(null), 0);
        AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
        image = op.filter(image, null);
        return image;
    }
View Full Code Here

            // Scale the image.
            BufferedImage thumb =
              new BufferedImage(thumbW, thumbH, img.getType());
            AffineTransform at =
              AffineTransform.getScaleInstance(scale, scale);
            AffineTransformOp ato = new AffineTransformOp(at, renderHints);
            ato.filter(img, thumb);

            // Save the image.
            Iterator<ImageWriter> iwi =
              ImageIO.getImageWritersBySuffix(suffix);
            if (! iwi.hasNext()) {
View Full Code Here

                if (img == null) {
                    return;
                }

                AffineTransformOp op = new AffineTransformOp(tr,
                        AffineTransformOp.TYPE_BILINEAR);
                img = op.filter(img, null);

                g2.setClip(null);

                g2.drawImage(
                        img,
                        0, 0, null);
                fullImage = false;
            } else {
                g2.setClip((int) pos.getX(), (int) pos.getY(),
                        (int) size.getX(), (int) size.getY());

                BufferedImage img = getMainCanvas().snapShot();

                if (img == null) {
                    return;
                }

                try {
                    img = img.getSubimage(
                            r.x, r.y, r.width, r.height);

                    AffineTransformOp op = new AffineTransformOp(tr,
                            AffineTransformOp.TYPE_BILINEAR);

                    img = op.filter(img, null);

                    g2.drawImage(
                            img,
                            (int) pos.getX(), (int) pos.getY(), null);
                } catch (Exception ex) {
View Full Code Here

        nx = r.getBounds2D().getX();
        image_at =new AffineTransform(Trm[0][0]*scale,-Trm[0][1]*scale,-Trm[1][0]*scale,Trm[1][1]*scale,-nx,-ny);
       
        //Create the affine operation.
        //ColorSpaces.hints causes single lines to vanish);
        AffineTransformOp invert;
        if((w>10)&(h>10))
          invert = new AffineTransformOp(image_at,  ColorSpaces.hints);
        else
          invert = new AffineTransformOp(image_at,  null);

        //scale image to produce final version
        if(scaleImage)
          current_image = invert.filter(current_image,null);       
       
      }
     
    }
View Full Code Here

        int image_h = current_image.getHeight();

        AffineTransform image_at =new AffineTransform();
        image_at.scale(1,-1);
        image_at.translate(0,-current_image.getHeight());
        AffineTransformOp invert= new AffineTransformOp(image_at,  ColorSpaces.hints);

        current_image = invert.filter(current_image,null);

                AffineTransform align_clip = new AffineTransform();

        double dx=-(CTM[2][0])*scale,dy= -((CTM[2][1])*scale);

        if(CTM[1][0]<0)
          dx=dx-CTM[1][0] ;
        if((CTM[0][0]<0)&&(CTM[1][0]>=0))
          dx=dx-CTM[1][0] ;

        if(CTM[0][1]<0)
          dy=dy-CTM[0][1];
        if(CTM[1][1]<0){
          if(CTM[0][1]>0)
            dy=dy-CTM[0][1];
          else if(CTM[1][1]<0)
            dy=dy-CTM[1][1];
        }
        align_clip.translate(dx,dy );

        final_clip.transform(align_clip);

        AffineTransform invert2=new AffineTransform(1/Trm2[0][0],0,0,1/Trm2[1][1],0,0);
        //System.out.println("invert2="+invert2);

                if((!alreadyTurned)||((Trm[1][0]==0)&&(Trm[0][1]==0)))
                final_clip.transform(invert2);

        //co-ords of transformed shape
        //reset sizes to remove area clipped
        int x = (int) final_clip.getBounds().getX();
        int y = (int) final_clip.getBounds().getY();
        int w = (int) final_clip.getBounds().getWidth();
        int h = (int) final_clip.getBounds().getHeight();

                //fix for 'mirror' image on Mac
                if(x<0)
                final_clip.transform(AffineTransform.getTranslateInstance(-x,0));

                /**
         * create inverse of clip and paint on to add transparency
         */
        Area inverseClip =new Area(new Rectangle(0,0,image_w,image_h));
        inverseClip.exclusiveOr(final_clip);
        Graphics2D image_g2 = current_image.createGraphics(); //g2 of canvas
        image_g2.setComposite(AlphaComposite.Clear);
        image_g2.fill(inverseClip);

        AffineTransform image_at2 =new AffineTransform();
        image_at2.scale(1,-1);
        image_at2.translate(0,-current_image.getHeight());
        AffineTransformOp invert3= new AffineTransformOp(image_at2,  ColorSpaces.hints);

                //mac os needs this stage!
        current_image=current_image.getSubimage(0,0,current_image.getWidth(),current_image.getHeight());

                current_image = invert3.filter(current_image,null);

                //Matrix.show(CTM);


                //get image (now clipped )
View Full Code Here

            if(a>5 || b>5 || c>5 || d>5)
            return;

            //Create the affine operation.
            //ColorSpaces.hints causes single lines to vanish);
            AffineTransformOp invert;


            if(w>1 && h>1){

                //fix image inversion if matrix (0,x,-y,0)
                if(CTM[0][0]==0 && CTM[1][1]==0 && CTM[0][1]>0 && CTM[1][0]<0){
                    image_at.scale(-1,1);
                    image_at.translate(-current_image.getWidth(),0);
                }
               
                invert = new AffineTransformOp(image_at,  ColorSpaces.hints);

            }else{

                //allow for line with changing values
                boolean isSolid=true;

                if(h==1){
                    //test all pixels set so we can keep a solid line
                    Raster ras=current_image.getRaster();
                    int bands=ras.getNumBands();
                    int width=ras.getWidth();
                    int[] elements=new int[(width*bands)+1];

                    ras.getPixels(0,0,width,1, elements);
                    for(int j=0;j<bands;j++){
                        int first=elements[0];
                        for(int i=1;i<width;i++){
                            if(elements[i*j]!=first){
                                isSolid=false;
                                i=width;
                                j=bands;
                            }
                        }
                    }
                }

                if(isSolid)
                    invert = new AffineTransformOp(image_at,  null);
                else
                    invert = new AffineTransformOp(image_at,  ColorSpaces.hints);
            }
            //ShowGUIMessage.showGUIMessage("x",current_image,"x");
            //if there is a rotation make image ARGB so we can clip
            if (CTM[1][0] != 0 || CTM[0][1] != 0)
                current_image = ColorSpaceConvertor.convertToARGB(current_image);

            //scale image to produce final version
            if(scaleImage){

                /**if not sheer/rotate, then bicubic*/
                if (true || CTM[1][0] != 0 || CTM[0][1] != 0){

                    if(h>1){

                        boolean imageProcessed=false;

                        //do not use
                        /**if(1==2 && ( h>32 && w>32 && JAIHelper.isJAIused() && (CTM[0][0]!=0 && CTM[1][1]!=-0))){ //don't use if small or rotation included

                            imageProcessed=true;

                            float iw=CTM[0][0];
                            if(iw==0)
                                iw=(int)CTM[0][1];

                            float ih=CTM[1][1];
                            if(ih==0)
                                ih=(int)CTM[1][0];

                            if(iw<0)
                                iw=-iw;
                            if(ih<0)
                                ih=-ih;

                            float xScale = iw/w;
                            float yScale = ih/h;

                            if(xScale==1.0 && yScale==1.0){

                            }else{

                                long start=System.currentTimeMillis();

                                java.awt.image.renderable.ParameterBlock pb = new java.awt.image.renderable.ParameterBlock();
                                pb.addSource(current_image); // The source image
                                pb.add(xScale);         // The xScale
                                pb.add(yScale);         // The yScale
                                pb.add(0.0F);           // The x translation
                                pb.add(0.0F);           // The y translation
                                pb.add(new javax.media.jai.InterpolationNearest()); // The interpolation

                                try{
                                    current_image = (javax.media.jai.JAI.create("scale", pb, null)).getAsBufferedImage();

                                    //if(timeChange==true)
                                    //  System.out.println("jai="+(System.currentTimeMillis()-start));
                                }catch(Exception ee){
                                    imageProcessed=false;

                                }catch(Error err){
                                    imageProcessed=false;
                                }
                            }

                            if(!imageProcessed) {
                                //System.err.println("Unable to use JAI for image");
                                LogWriter.writeLog("Unable to use JAI for image");
                            }

                        } /**/


                        if(!imageProcessed){
                            //long start=System.currentTimeMillis();

                            boolean failed=false;
                            //allow for odd behaviour on some files
                            try{
                                current_image = invert.filter(current_image,null);
                            }catch(Exception e){
                                failed=true;
                            }
                            if(failed){
                                try{
                                    invert = new AffineTransformOp(image_at,null);
                                    current_image = invert.filter(current_image,null);
                                }catch(Exception e){
                                }
                            }
                            //if(timeChange==true)
                            //  System.out.println("non-jai="+(System.currentTimeMillis()-start));
                        }
                    }
                }else{

                    int dx=1,dy=1;

                    /**workout size and if needs to be inverted*/
                    w=(int)CTM[0][0];
                    if(w==0)
                        w=(int)CTM[0][1];
                    h=(int)CTM[1][1];
                    if(h==0)
                        h=(int)CTM[1][0];

                    if(w<0){
                        w=-w;
                        dx=-1;
                    }
                    if(h<0){
                        h=-h;
                        dy=-1;
                    }

                    /**turn around if needed*/
                    if(dx==-1 || dy==-1){

                        image_at =new AffineTransform();
                        image_at.scale(dx,dy);

                        if(dx==-1)
                            image_at.translate(-current_image.getWidth(),0);
                        if(dy==-1)
                            image_at.translate(0,-current_image.getHeight());

                        //Create the affine operation.
                        invert = new AffineTransformOp(image_at,  ColorSpaces.hints);
                        current_image = invert.filter(current_image,null);

                    }

                    Image scaledImage= current_image.getScaledInstance(w,h,BufferedImage.SCALE_SMOOTH);

View Full Code Here

        //turn upside down
      AffineTransform image_at2 =new AffineTransform();
      image_at2.scale(1,-1);
      image_at2.translate(0,-image.getHeight());

      AffineTransformOp invert3= new AffineTransformOp(image_at2,  ColorSpaces.hints);

      boolean imageProcessed=false;

      if(JAIHelper.isJAIused()){

        imageProcessed=true;

        try{
          image = (javax.media.jai.JAI.create("affine", image, image_at2, new javax.media.jai.InterpolationNearest())).getAsBufferedImage();
        }catch(Exception ee){
          imageProcessed=false;
          ee.printStackTrace();
        }catch(Error err){
          imageProcessed=false;
          err.printStackTrace();
        }

        if(!imageProcessed && LogWriter.isOutput())
          LogWriter.writeLog("Unable to use JAI for image inversion");

      }

      if(!imageProcessed){

        if(image.getType()==12){ //avoid turning into ARGB

          BufferedImage source=image;
          image =new BufferedImage(source.getWidth(),source.getHeight(),source.getType());

          invert3.filter(source,image);
        }else{

          boolean failed=false;
          //allow for odd behaviour on some files
          try{
            image = invert3.filter(image,null);
          }catch(Exception e){
            failed=true;
          }
          if(failed){
            try{
              invert3 = new AffineTransformOp(image_at2,null);
              image = invert3.filter(image,null);
            }catch(Exception e){
            }
          }
        }
      }
View Full Code Here

        //23032012 - disabled by Mark as breaks with new print code
    if(1==2 && image.getType()==BufferedImage.TYPE_BYTE_GRAY &&
        image.getHeight()< 43 && !isPrinting){
     
      //This is how we fix the gray scale image
      AffineTransformOp op = new AffineTransformOp(upside_down, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
      g2.drawImage(image, op, 0, 0);
     
    }else{
     
      //Draw image as normal
      g2.drawImage(image, upside_down, null);
   
    }
   
    if (isClipReset) {
        g2.setClip(g2clip);
    }

      } catch (Exception e) {
      }
  } else {

      try {

    if (applyTransform) {
        AffineTransformOp invert = new AffineTransformOp(upside_down, ColorSpaces.hints);
        image = invert.filter(image, null);
    }

    g2.translate(x, y);

    if (optimisedTurnCode && (optionsApplied & PDFImageProcessing.TURN_ON_DRAW) == PDFImageProcessing.TURN_ON_DRAW) {
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.