Examples of AffineTransformOp


Examples of java.awt.image.AffineTransformOp

  private void testRotation(TestHarness harness)
  {
    harness.checkPoint("testRotation");

    AffineTransform xform = AffineTransform.getRotateInstance(Math.PI / 2);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(-5,5));

    // Do it again, but result in a diamond (not another level rectangle)
    xform.rotate(Math.PI / 3);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(-6.830127018922193, -1.8301270189221923));
   
    // Rotation about a point
    xform.setToIdentity();
    xform.rotate(Math.PI / 2, 10, 2);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(7,-3));
  }
View Full Code Here

Examples of java.awt.image.AffineTransformOp

  private void testScale(TestHarness harness)
  {
    harness.checkPoint("testScale");
   
    AffineTransform xform = AffineTransform.getScaleInstance(1.0, 1.0);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(5, 5));
   
    xform.scale(2.5, 4.75);
    op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(12.5,23.75));
  }
View Full Code Here

Examples of java.awt.image.AffineTransformOp

  private void testShear(TestHarness harness)
  {
    harness.checkPoint("testShear");
   
    AffineTransform xform = AffineTransform.getShearInstance(1.5, 3.25);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(12.5,21.25));
  }
View Full Code Here

Examples of java.awt.image.AffineTransformOp

  private void testTranslation(TestHarness harness)
  {
    harness.checkPoint("testTranslation");

    AffineTransform xform = AffineTransform.getTranslateInstance(75, 50);
    AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_BICUBIC);
    harness.check(op.getPoint2D(new Point2D.Double(5, 5), null), new Point2D.Double(80,55));
  }
View Full Code Here

Examples of java.awt.image.AffineTransformOp

                    g.dispose();
                }
               
                AffineTransform trans = AffineTransform.getRotateInstance(Math.PI/2,0,0);
                trans.translate(0,-src.getHeight());
                BufferedImageOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                op.filter(src,dst);
                setImage(dst);
            }
        };
        action.putValue(Action.NAME,"Rotate Clockwise");
        return action;       
View Full Code Here

Examples of java.awt.image.AffineTransformOp

                } finally {
                    g.dispose();
                }
                AffineTransform trans = AffineTransform.getRotateInstance(-Math.PI/2,0,0);
                trans.translate(-src.getWidth(),0);
                BufferedImageOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
                op.filter(src,dst);
                setImage(dst);
            }
        };
        action.putValue(Action.NAME, "Rotate CounterClockwise");
        return action;       
View Full Code Here

Examples of java.awt.image.AffineTransformOp

        List<String> sizeTypeList = UtilMisc.toList("small", "medium", "large", "detail");
        int index;
        Map<String, Map<String, String>> imgPropertyMap = FastMap.newInstance();
        BufferedImage bufImg, bufNewImg;
        double imgHeight, imgWidth, scaleFactor;
        AffineTransformOp op;
        Map<String, String> imgUrlMap = FastMap.newInstance();
        Map<String, Object> resultXMLMap = FastMap.newInstance();
        Map<String, Object> resultBufImgMap = FastMap.newInstance();
        Map<String, Object> resultScaleImgMap = FastMap.newInstance();
        Map<String, Object> result = FastMap.newInstance();

        /* ImageProperties.xml */
        String imgPropertyFullPath = System.getProperty("ofbiz.home") + "/applications/product/config/ImageProperties.xml";
        resultXMLMap.putAll((Map<String, Object>) ImageTransform.getXMLValue(imgPropertyFullPath, locale));
        if (resultXMLMap.containsKey("responseMessage") && resultXMLMap.get("responseMessage").equals("success")) {
            imgPropertyMap.putAll((Map<String, Map<String, String>>) resultXMLMap.get("xml"));
        } else {
            String errMsg = UtilProperties.getMessage(resource, "ScaleImage.unable_to_parse", locale) + " : ImageProperties.xml";
            Debug.logError(errMsg, module);
            result.put("errorMessage", errMsg);
            return result;
        }

        /* IMAGE */
        // get Name and Extension
        index = filenameToUse.lastIndexOf(".");
        String imgName = filenameToUse.substring(0, index - 1);
        String imgExtension = filenameToUse.substring(index + 1);
        // paths
        String mainFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.format");
        String imageServerPath = FlexibleStringExpander.expandString(UtilProperties.getPropertyValue("catalog", "image.server.path"), context);
        String imageUrlPrefix = UtilProperties.getPropertyValue("catalog", "image.url.prefix");

        String id = null;
        String type = null;
        if (viewType.toLowerCase().contains("main")) {
            type = "original";
            id = imgName;
        } else if (viewType.toLowerCase().contains("additional") && viewNumber != null && !viewNumber.equals("0")) {
            type = "additional";
            id = imgName + "_View_" + viewNumber;
        } else {
            return ServiceUtil.returnError("View Type : " + type + " is wrong");
        }
        FlexibleStringExpander mainFilenameExpander = FlexibleStringExpander.getInstance(mainFilenameFormat);
        String fileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", type, "id", filenameToUse));
        String filePathPrefix = "";
        if (fileLocation.lastIndexOf("/") != -1) {
            filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
        }



        /* get original BUFFERED IMAGE */
        resultBufImgMap.putAll(ImageTransform.getBufferedImage(imageServerPath + "/" + filePathPrefix + filenameToUse, locale));

        if (resultBufImgMap.containsKey("responseMessage") && resultBufImgMap.get("responseMessage").equals("success")) {
            bufImg = (BufferedImage) resultBufImgMap.get("bufferedImage");

            // get Dimensions
            imgHeight = (double) bufImg.getHeight();
            imgWidth = (double) bufImg.getWidth();
            if (imgHeight == 0.0 || imgWidth == 0.0) {
                String errMsg = UtilProperties.getMessage(resource, "ScaleImage.one_current_image_dimension_is_null", locale) + " : imgHeight = " + imgHeight + " ; imgWidth = " + imgWidth;
                Debug.logError(errMsg, module);
                result.put("errorMessage", errMsg);
                return result;
            }

            // new Filename Format
            FlexibleStringExpander addFilenameExpander = mainFilenameExpander;
            if (viewType.toLowerCase().contains("additional")) {
                String addFilenameFormat = UtilProperties.getPropertyValue("catalog", "image.filename.additionalviewsize.format");
                addFilenameExpander = FlexibleStringExpander.getInstance(addFilenameFormat);
            }

            /* scale Image for each Size Type */
            Iterator<String> sizeIter = sizeTypeList.iterator();
            while (sizeIter.hasNext()) {
                String sizeType = sizeIter.next();

                resultScaleImgMap.putAll(ImageTransform.scaleImage(bufImg, imgHeight, imgWidth, imgPropertyMap, sizeType, locale));

                if (resultScaleImgMap.containsKey("responseMessage") && resultScaleImgMap.get("responseMessage").equals("success")) {
                    bufNewImg = (BufferedImage) resultScaleImgMap.get("bufferedImage");
                    Double scaleFactorDb = (Double) resultScaleImgMap.get("scaleFactor");
                    scaleFactor = scaleFactorDb.doubleValue();

                    // define Interpolation
                    Map<RenderingHints.Key, Object> rhMap = FastMap.newInstance();
                        rhMap.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
                        rhMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                        rhMap.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
                        rhMap.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
                        rhMap.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
                        rhMap.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                        rhMap.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
                        //rhMap.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
                        rhMap.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                    RenderingHints rh = new RenderingHints(rhMap);

                    /* IMAGE TRANFORMATION */
                    AffineTransform tx = new AffineTransform();
                    tx.scale(scaleFactor, scaleFactor);


                    try {
                        op = new AffineTransformOp(tx, rh);
                    } catch (ImagingOpException e) {
                        String errMsg = UtilProperties.getMessage(resource, "ScaleImage.transform_is_non_invertible", locale+ e.toString();
                        Debug.logError(errMsg, module);
                        result.put("errorMessage", errMsg);
                        return result;
                    }

                    // write the New Scaled Image
                    String newFileLocation = null;
                    if (viewType.toLowerCase().contains("main")) {
                        newFileLocation = mainFilenameExpander.expandString(UtilMisc.toMap("location", "products", "type", sizeType, "id", id));
                    } else if (viewType.toLowerCase().contains("additional")) {
                        newFileLocation = addFilenameExpander.expandString(UtilMisc.toMap("location", "products", "viewtype", viewType, "sizetype", sizeType,"id", id));
                    }
                    String newFilePathPrefix = "";
                    if (newFileLocation.lastIndexOf("/") != -1) {
                        newFilePathPrefix = newFileLocation.substring(0, newFileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash
                    }

                    String targetDirectory = imageServerPath + "/" + newFilePathPrefix;
                    File targetDir = new File(targetDirectory);
                    if (!targetDir.exists()) {
                        boolean created = targetDir.mkdirs();
                        if (!created) {
                            String errMsg = UtilProperties.getMessage(resource, "ScaleImage.unable_to_create_target_directory", locale) + " - " + targetDirectory;
                            Debug.logFatal(errMsg, module);
                            return ServiceUtil.returnError(errMsg);
                        }
                    }

                    // write new image
                    try {
                        ImageIO.write(op.filter(bufImg, bufNewImg), imgExtension, new File(imageServerPath + "/" + newFilePathPrefix + filenameToUse));
                    } catch (IllegalArgumentException e) {
                        String errMsg = UtilProperties.getMessage(resource, "ScaleImage.one_parameter_is_null", locale) + e.toString();
                        Debug.logError(errMsg, module);
                        result.put("errorMessage", errMsg);
                        return result;
View Full Code Here

Examples of java.awt.image.AffineTransformOp

            // Scale texture image, cutting border if needed
            BufferedImage src = new BufferedImage(TEXSIZE, TEXSIZE, BufferedImage.TYPE_INT_ARGB);
            AffineTransform at = new AffineTransform();
            at.scale(TEXSIZE/(double)(w-border_cut*2), TEXSIZE/(double)(h-border_cut*2));
            at.translate(-w/2-border_cut, -h/2-border_cut);
            AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
            ato.filter(tmp, src);

            if (border_add > 0) {
                // Add border if needed
                Graphics2D gr = src.createGraphics();
                gr.setColor(Color.DARK_GRAY);
View Full Code Here

Examples of java.awt.image.AffineTransformOp

    private void writeResized(BufferedImage image, double scale, ImageWriter format, String name, File root) throws IOException {
        BufferedImage scaledImage = null;
        if (Math.abs(scale - 1.0) > 0.001) {
            AffineTransform xform = AffineTransform.getScaleInstance(scale, scale);
            AffineTransformOp op  = new AffineTransformOp(xform, AffineTransformOp.TYPE_BILINEAR);
            Rectangle2D dim = op.getBounds2D(image);
            scaledImage = new BufferedImage(
                (int)dim.getMaxX(),
                (int)dim.getMaxY(),
                image.getType()
            );
            scaledImage = op.filter(image, scaledImage);
        } else {
            scaledImage = image;
        }

        File f = new File(root, name);
View Full Code Here

Examples of java.awt.image.AffineTransformOp

            interpolationtype=TYPE_BILINEAR;

            setBackGroundColor(new Color(0.0f,0.0f,0.0f));
            image=null;
            setPreferredSize(new Dimension(320,200));
            aff=new AffineTransformOp(new AffineTransform(referential.scalex,0,0,referential.scaley,0,0) , interpolationtype);
            //setBorder(new EmptyBorder(0,0,0,0));// enlever le border
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.