Search in sources :

Example 16 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.

the class GcSnapshot method restoreLayer.

private void restoreLayer(Layer dstLayer) {
    Graphics2D baseGfx = dstLayer.getImage().createGraphics();
    // if the layer contains an original copy this means the flags
    // didn't restrict drawing to the local layer and we need to make sure the
    // layer bounds in the layer beneath didn't receive any drawing.
    // so we use the originalCopy to erase the new drawings in there.
    BufferedImage originalCopy = dstLayer.getOriginalCopy();
    if (originalCopy != null) {
        Graphics2D g = (Graphics2D) baseGfx.create();
        g.setComposite(AlphaComposite.Src);
        g.drawImage(originalCopy, mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom, 0, 0, mLayerBounds.width(), mLayerBounds.height(), null);
        g.dispose();
    }
    // now draw put the content of the local layer onto the layer,
    // using the paint information
    Graphics2D g = createCustomGraphics(baseGfx, mLocalLayerPaint, true, /*alphaOnly*/
    0);
    g.drawImage(mLocalLayer.getImage(), mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom, mLayerBounds.left, mLayerBounds.top, mLayerBounds.right, mLayerBounds.bottom, null);
    g.dispose();
    baseGfx.dispose();
}
Also used : BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 17 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.

the class ShadowPainter method createRectangularDropShadow.

/**
     * Draws a rectangular drop shadow (of size {@link #SHADOW_SIZE} by {@link #SHADOW_SIZE} around
     * the given source and returns a new image with both combined
     *
     * @param source the source image
     *
     * @return the source image with a drop shadow on the bottom and right
     */
@SuppressWarnings("UnusedDeclaration")
public static BufferedImage createRectangularDropShadow(BufferedImage source) {
    int type = source.getType();
    if (type == BufferedImage.TYPE_CUSTOM) {
        type = BufferedImage.TYPE_INT_ARGB;
    }
    int width = source.getWidth();
    int height = source.getHeight();
    BufferedImage image;
    image = new BufferedImage(width + SHADOW_SIZE, height + SHADOW_SIZE, type);
    Graphics2D g = image.createGraphics();
    g.drawImage(source, 0, 0, null);
    drawRectangleShadow(image, 0, 0, width, height);
    g.dispose();
    return image;
}
Also used : BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 18 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.

the class ShadowPainter method createSmallRectangularDropShadow.

/**
     * Draws a small rectangular drop shadow (of size {@link #SMALL_SHADOW_SIZE} by {@link
     * #SMALL_SHADOW_SIZE} around the given source and returns a new image with both combined
     *
     * @param source the source image
     *
     * @return the source image with a drop shadow on the bottom and right
     */
@SuppressWarnings("UnusedDeclaration")
public static BufferedImage createSmallRectangularDropShadow(BufferedImage source) {
    int type = source.getType();
    if (type == BufferedImage.TYPE_CUSTOM) {
        type = BufferedImage.TYPE_INT_ARGB;
    }
    int width = source.getWidth();
    int height = source.getHeight();
    BufferedImage image;
    image = new BufferedImage(width + SMALL_SHADOW_SIZE, height + SMALL_SHADOW_SIZE, type);
    Graphics2D g = image.createGraphics();
    g.drawImage(source, 0, 0, null);
    drawSmallRectangleShadow(image, 0, 0, width, height);
    g.dispose();
    return image;
}
Also used : BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 19 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.

the class ViewGroup_Delegate method getPathShadow.

private static BufferedImage getPathShadow(Outline outline, Canvas canvas, float elevation) {
    Rect clipBounds = canvas.getClipBounds();
    if (clipBounds.isEmpty()) {
        return null;
    }
    BufferedImage image = new BufferedImage(clipBounds.width(), clipBounds.height(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.draw(Path_Delegate.getDelegate(outline.mPath.mNativePath).getJavaShape());
    graphics.dispose();
    return ShadowPainter.createDropShadow(image, (int) elevation);
}
Also used : Rect(android.graphics.Rect) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 20 with Graphics2D

use of java.awt.Graphics2D in project android_frameworks_base by ResurrectionRemix.

the class Canvas_Delegate method drawBitmap.

private static void drawBitmap(long nativeCanvas, Bitmap_Delegate bitmap, long nativePaintOrZero, final int sleft, final int stop, final int sright, final int sbottom, final int dleft, final int dtop, final int dright, final int dbottom) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas);
    if (canvasDelegate == null) {
        return;
    }
    // get the paint, which could be null if the int is 0
    Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nativePaintOrZero);
    final BufferedImage image = getImageToDraw(bitmap, paintDelegate, sBoolOut);
    draw(nativeCanvas, nativePaintOrZero, true, /*compositeOnly*/
    sBoolOut[0], new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            if (paint != null && paint.isFilterBitmap()) {
                graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            }
            //FIXME add support for canvas, screen and bitmap densities.
            graphics.drawImage(image, dleft, dtop, dright, dbottom, sleft, stop, sright, sbottom, null);
        }
    });
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Graphics2D (java.awt.Graphics2D)1716 BufferedImage (java.awt.image.BufferedImage)809 Color (java.awt.Color)394 BasicStroke (java.awt.BasicStroke)186 Font (java.awt.Font)161 Point (java.awt.Point)145 AffineTransform (java.awt.geom.AffineTransform)140 Rectangle (java.awt.Rectangle)139 IOException (java.io.IOException)112 Rectangle2D (java.awt.geom.Rectangle2D)100 Dimension (java.awt.Dimension)92 Image (java.awt.Image)91 GradientPaint (java.awt.GradientPaint)90 FontMetrics (java.awt.FontMetrics)87 Paint (java.awt.Paint)82 Graphics (java.awt.Graphics)79 File (java.io.File)65 Point2D (java.awt.geom.Point2D)59 Stroke (java.awt.Stroke)55 ImageIcon (javax.swing.ImageIcon)50