當前位置: 首頁>>代碼示例>>Java>>正文


Java AffineTransform.preConcatenate方法代碼示例

本文整理匯總了Java中java.awt.geom.AffineTransform.preConcatenate方法的典型用法代碼示例。如果您正苦於以下問題:Java AffineTransform.preConcatenate方法的具體用法?Java AffineTransform.preConcatenate怎麽用?Java AffineTransform.preConcatenate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.geom.AffineTransform的用法示例。


在下文中一共展示了AffineTransform.preConcatenate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractRotation

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
private static AffineTransform extractRotation(Point2D.Double pt,
    AffineTransform tx, boolean andTranslation) {

    tx.deltaTransform(pt, pt);
    AffineTransform rtx = AffineTransform.getRotateInstance(pt.x, pt.y);

    try {
        AffineTransform rtxi = rtx.createInverse();
        double dx = tx.getTranslateX();
        double dy = tx.getTranslateY();
        tx.preConcatenate(rtxi);
        if (andTranslation) {
            if (dx != 0 || dy != 0) {
                tx.setTransform(tx.getScaleX(), tx.getShearY(),
                                tx.getShearX(), tx.getScaleY(), 0, 0);
                rtx.setTransform(rtx.getScaleX(), rtx.getShearY(),
                                 rtx.getShearX(), rtx.getScaleY(), dx, dy);
            }
        }
    }
    catch (NoninvertibleTransformException e) {
        return null;
    }
    return rtx;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:AttributeValues.java

示例2: girar

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * Rotaciona uma imagem
 *
 * @param image imagem a ser rotacionada
 * @param angle ângulo da rotação
 * @return imagem rotacionada
 */
public static ImageIcon girar(ImageIcon image, double angle) {
    BufferedImage rotateImage = ImageIconToBufferedImage(image);
    angle %= 360;
    if (angle < 0) {
        angle += 360;
    }
    AffineTransform tx = new AffineTransform();
    tx.rotate(Math.toRadians(angle), rotateImage.getWidth() / 2.0, rotateImage.getHeight() / 2.0);

    double ytrans;
    double xtrans;
    if (angle <= 90) {
        xtrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getX();
        ytrans = tx.transform(new Point2D.Double(0.0, 0.0), null).getY();
    } else if (angle <= 180) {
        xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getX();
        ytrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getY();
    } else if (angle <= 270) {
        xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getX();
        ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getY();
    } else {
        xtrans = tx.transform(new Point2D.Double(0, 0), null).getX();
        ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getY();
    }

    AffineTransform translationTransform = new AffineTransform();
    translationTransform.translate(-xtrans, -ytrans);
    tx.preConcatenate(translationTransform);

    return new ImageIcon(new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR).filter(rotateImage, null));
}
 
開發者ID:limagiran,項目名稱:hearthstone,代碼行數:39,代碼來源:Img.java

示例3: rotate

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
public ImageUtils rotate(int angle){
    if (angle == 0) {
        return this;
    }

    if (angle>360) {
        angle = Math.abs(angle)%360;
    }

    if (angle<0){
        if (Math.abs(angle)<360) {
            angle = 360+angle;
        }else {
            angle =(Math.abs(angle)/360+1)*360+angle;
        }
    }

    int width = this.dealedImage.getWidth();
    int height = this.dealedImage.getHeight();
    int new_w, new_h;
    int new_radian = angle;
    if (angle <= 90) {
        new_w = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
        new_h = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
    } else if (angle <= 180) {
        new_radian = angle - 90;
        new_w = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
        new_h = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
    } else if (angle <= 270) {
        new_radian = angle - 180;
        new_w = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
        new_h = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
    } else {
        new_radian = angle - 270;
        new_w = (int) (height * Math.cos(Math.toRadians(new_radian)) + width * Math.sin(Math.toRadians(new_radian)));
        new_h = (int) (width * Math.cos(Math.toRadians(new_radian)) + height * Math.sin(Math.toRadians(new_radian)));
    }
    BufferedImage toStore = new BufferedImage(new_w, new_h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = toStore.createGraphics();
    AffineTransform affineTransform = new AffineTransform();
    affineTransform.rotate(Math.toRadians(angle), width / 2, height / 2);
    if (angle != 180) {
        AffineTransform translationTransform = this.findTranslation(affineTransform, this.dealedImage, angle);
        affineTransform.preConcatenate(translationTransform);
    }
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, new_w, new_h);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawRenderedImage(this.dealedImage, affineTransform);
    g.dispose();
    this.dealedImage = toStore;

    return this;
}
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:55,代碼來源:ImageUtils.java

示例4: setRadialGradientPaint

import java.awt.geom.AffineTransform; //導入方法依賴的package包/類
/**
 * This method calculates six m** values and a focusX value that
 * are used by the native fragment shader.  These techniques are
 * based on a whitepaper by Daniel Rice on radial gradient performance
 * (attached to the bug report for 6521533).  One can refer to that
 * document for the complete set of formulas and calculations, but
 * the basic goal is to compose a transform that will convert an
 * (x,y) position in device space into a "u" value that represents
 * the relative distance to the gradient focus point.  The resulting
 * value can be used to look up the appropriate color by linearly
 * interpolating between the two nearest colors in the gradient.
 */
private static void setRadialGradientPaint(RenderQueue rq,
                                           SunGraphics2D sg2d,
                                           RadialGradientPaint paint,
                                           boolean useMask)
{
    boolean linear =
        (paint.getColorSpace() == ColorSpaceType.LINEAR_RGB);
    int cycleMethod = paint.getCycleMethod().ordinal();
    float[] fractions = paint.getFractions();
    Color[] colors = paint.getColors();
    int numStops = colors.length;
    int[] pixels = convertToIntArgbPrePixels(colors, linear);
    Point2D center = paint.getCenterPoint();
    Point2D focus = paint.getFocusPoint();
    float radius = paint.getRadius();

    // save original (untransformed) center and focus points
    double cx = center.getX();
    double cy = center.getY();
    double fx = focus.getX();
    double fy = focus.getY();

    // transform from gradient coords to device coords
    AffineTransform at = paint.getTransform();
    at.preConcatenate(sg2d.transform);
    focus = at.transform(focus, focus);

    // transform unit circle to gradient coords; we start with the
    // unit circle (center=(0,0), focus on positive x-axis, radius=1)
    // and then transform into gradient space
    at.translate(cx, cy);
    at.rotate(fx - cx, fy - cy);
    at.scale(radius, radius);

    // invert to get mapping from device coords to unit circle
    try {
        at.invert();
    } catch (Exception e) {
        at.setToScale(0.0, 0.0);
    }
    focus = at.transform(focus, focus);

    // clamp the focus point so that it does not rest on, or outside
    // of, the circumference of the gradient circle
    fx = Math.min(focus.getX(), 0.99);

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacity(20 + 28 + (numStops*4*2));
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_RADIAL_GRADIENT_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(linear  ? 1 : 0);
    buf.putInt(numStops);
    buf.putInt(cycleMethod);
    buf.putFloat((float)at.getScaleX());
    buf.putFloat((float)at.getShearX());
    buf.putFloat((float)at.getTranslateX());
    buf.putFloat((float)at.getShearY());
    buf.putFloat((float)at.getScaleY());
    buf.putFloat((float)at.getTranslateY());
    buf.putFloat((float)fx);
    buf.put(fractions);
    buf.put(pixels);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:77,代碼來源:BufferedPaints.java


注:本文中的java.awt.geom.AffineTransform.preConcatenate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。