Search in sources :

Example 41 with AffineTransform

use of java.awt.geom.AffineTransform in project zxing by zxing.

the class AbstractBlackBoxTestCase method rotateImage.

protected static BufferedImage rotateImage(BufferedImage original, float degrees) {
    if (degrees == 0.0f) {
        return original;
    }
    switch(original.getType()) {
        case BufferedImage.TYPE_BYTE_INDEXED:
        case BufferedImage.TYPE_BYTE_BINARY:
            BufferedImage argb = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics g = argb.createGraphics();
            g.drawImage(original, 0, 0, null);
            g.dispose();
            original = argb;
            break;
    }
    double radians = Math.toRadians(degrees);
    // Transform simply to find out the new bounding box (don't actually run the image through it)
    AffineTransform at = new AffineTransform();
    at.rotate(radians, original.getWidth() / 2.0, original.getHeight() / 2.0);
    BufferedImageOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    RectangularShape r = op.getBounds2D(original);
    int width = (int) Math.ceil(r.getWidth());
    int height = (int) Math.ceil(r.getHeight());
    // Real transform, now that we know the size of the new image and how to translate after we rotate
    // to keep it centered
    at = new AffineTransform();
    at.rotate(radians, width / 2.0, height / 2.0);
    at.translate((width - original.getWidth()) / 2.0, (height - original.getHeight()) / 2.0);
    op = new AffineTransformOp(at, AffineTransformOp.TYPE_BICUBIC);
    return op.filter(original, new BufferedImage(width, height, original.getType()));
}
Also used : Graphics(java.awt.Graphics) BufferedImageOp(java.awt.image.BufferedImageOp) RectangularShape(java.awt.geom.RectangularShape) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 42 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by DirtyUnicorns.

the class Matrix_Delegate method native_invert.

@LayoutlibDelegate
static /*package*/
boolean native_invert(long native_object, long inverse) {
    Matrix_Delegate d = sManager.getDelegate(native_object);
    if (d == null) {
        return false;
    }
    Matrix_Delegate inv_mtx = sManager.getDelegate(inverse);
    if (inv_mtx == null) {
        return false;
    }
    try {
        AffineTransform affineTransform = d.getAffineTransform();
        AffineTransform inverseTransform = affineTransform.createInverse();
        inv_mtx.mValues[0] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[1] = (float) inverseTransform.getShearX();
        inv_mtx.mValues[2] = (float) inverseTransform.getTranslateX();
        inv_mtx.mValues[3] = (float) inverseTransform.getScaleX();
        inv_mtx.mValues[4] = (float) inverseTransform.getShearY();
        inv_mtx.mValues[5] = (float) inverseTransform.getTranslateY();
        return true;
    } catch (NoninvertibleTransformException e) {
        return false;
    }
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 43 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by DirtyUnicorns.

the class Canvas_Delegate method native_concat.

@LayoutlibDelegate
public static void native_concat(long nCanvas, long nMatrix) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
    if (canvasDelegate == null) {
        return;
    }
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
    if (matrixDelegate == null) {
        return;
    }
    // get the current top graphics2D object.
    GcSnapshot snapshot = canvasDelegate.getSnapshot();
    // get its current matrix
    AffineTransform currentTx = snapshot.getTransform();
    // get the AffineTransform of the given matrix
    AffineTransform matrixTx = matrixDelegate.getAffineTransform();
    // combine them so that the given matrix is applied after.
    currentTx.concatenate(matrixTx);
    // give it to the graphics2D as a new matrix replacing all previous transform
    snapshot.setTransform(currentTx);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 44 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by DirtyUnicorns.

the class Region_Delegate method translate.

@LayoutlibDelegate
static /*package*/
void translate(Region thisRegion, int dx, int dy, Region dst) {
    Region_Delegate regionDelegate = sManager.getDelegate(thisRegion.mNativeRegion);
    if (regionDelegate == null) {
        return;
    }
    Region_Delegate targetRegionDelegate = sManager.getDelegate(dst.mNativeRegion);
    if (targetRegionDelegate == null) {
        return;
    }
    if (regionDelegate.mArea.isEmpty()) {
        targetRegionDelegate.mArea = new Area();
    } else {
        targetRegionDelegate.mArea = new Area(regionDelegate.mArea);
        AffineTransform mtx = new AffineTransform();
        mtx.translate(dx, dy);
        targetRegionDelegate.mArea.transform(mtx);
    }
}
Also used : Area(java.awt.geom.Area) AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 45 with AffineTransform

use of java.awt.geom.AffineTransform in project android_frameworks_base by DirtyUnicorns.

the class Canvas_Delegate method native_getCTM.

@LayoutlibDelegate
public static void native_getCTM(long canvas, long matrix) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas);
    if (canvasDelegate == null) {
        return;
    }
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix);
    if (matrixDelegate == null) {
        return;
    }
    AffineTransform transform = canvasDelegate.getSnapshot().getTransform();
    matrixDelegate.set(Matrix_Delegate.makeValues(transform));
}
Also used : AffineTransform(java.awt.geom.AffineTransform) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

AffineTransform (java.awt.geom.AffineTransform)370 BufferedImage (java.awt.image.BufferedImage)60 Graphics2D (java.awt.Graphics2D)54 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)42 Rectangle2D (java.awt.geom.Rectangle2D)40 Point2D (java.awt.geom.Point2D)28 Shape (java.awt.Shape)24 Font (java.awt.Font)23 Paint (java.awt.Paint)23 GcSnapshot (com.android.layoutlib.bridge.impl.GcSnapshot)20 ArrayList (java.util.ArrayList)18 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)17 Rectangle (java.awt.Rectangle)16 PathIterator (java.awt.geom.PathIterator)16 Color (java.awt.Color)15 Point (java.awt.Point)15 FontRenderContext (java.awt.font.FontRenderContext)15 Area (java.awt.geom.Area)14 GeneralPath (java.awt.geom.GeneralPath)14 AffineTransformOp (java.awt.image.AffineTransformOp)13