Search in sources :

Example 11 with Graphics2D

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

the class Bitmap_Delegate method nativeErase.

@LayoutlibDelegate
static /*package*/
void nativeErase(int nativeBitmap, int color) {
    // get the delegate from the native int.
    Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap);
    if (delegate == null) {
        return;
    }
    BufferedImage image = delegate.mImage;
    Graphics2D g = image.createGraphics();
    try {
        g.setColor(new java.awt.Color(color, true));
        g.fillRect(0, 0, image.getWidth(), image.getHeight());
    } finally {
        g.dispose();
    }
}
Also used : BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 12 with Graphics2D

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

the class Canvas_Delegate method nativeDrawBitmapMatrix.

@LayoutlibDelegate
static /*package*/
void nativeDrawBitmapMatrix(int nCanvas, int nBitmap, int nMatrix, int nPaint) {
    // get the delegate from the native int.
    Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas);
    if (canvasDelegate == null) {
        return;
    }
    // get the delegate from the native int, which can be null
    Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint);
    // get the delegate from the native int.
    Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nBitmap);
    if (bitmapDelegate == null) {
        return;
    }
    final BufferedImage image = getImageToDraw(bitmapDelegate, paintDelegate, sBoolOut);
    Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix);
    if (matrixDelegate == null) {
        return;
    }
    final AffineTransform mtx = matrixDelegate.getAffineTransform();
    canvasDelegate.getSnapshot().draw(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, mtx, null);
        }
    }, paintDelegate, true, /*compositeOnly*/
    false);
}
Also used : AffineTransform(java.awt.geom.AffineTransform) GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 13 with Graphics2D

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

the class RenderDrawable method getImage.

protected BufferedImage getImage(int w, int h) {
    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gc = image.createGraphics();
    gc.setComposite(AlphaComposite.Src);
    gc.setColor(new Color(0x00000000, true));
    gc.fillRect(0, 0, w, h);
    // done
    gc.dispose();
    return image;
}
Also used : Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 14 with Graphics2D

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

the class GcSnapshot method drawInLayer.

private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint, boolean compositeOnly, boolean forceSrcMode) {
    Graphics2D originalGraphics = layer.getGraphics();
    // get a Graphics2D object configured with the drawing parameters.
    Graphics2D configuredGraphics2D = paint != null ? createCustomGraphics(originalGraphics, paint, compositeOnly, forceSrcMode) : (Graphics2D) originalGraphics.create();
    try {
        drawable.draw(configuredGraphics2D, paint);
        layer.change();
    } finally {
        // dispose Graphics2D object
        configuredGraphics2D.dispose();
    }
}
Also used : Graphics2D(java.awt.Graphics2D)

Example 15 with Graphics2D

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

the class GcSnapshot method drawInLayer.

private void drawInLayer(Layer layer, Drawable drawable, Paint_Delegate paint, boolean compositeOnly, int forceMode) {
    Graphics2D originalGraphics = layer.getGraphics();
    if (paint == null) {
        drawOnGraphics((Graphics2D) originalGraphics.create(), drawable, null, /*paint*/
        layer);
    } else {
        ColorFilter_Delegate filter = paint.getColorFilter();
        if (filter == null || !filter.isSupported()) {
            // get a Graphics2D object configured with the drawing parameters.
            Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, compositeOnly, forceMode);
            drawOnGraphics(configuredGraphics, drawable, paint, layer);
            return;
        }
        int x = 0;
        int y = 0;
        int width;
        int height;
        Rectangle clipBounds = originalGraphics.getClipBounds();
        if (clipBounds != null) {
            if (clipBounds.width == 0 || clipBounds.height == 0) {
                // Clip is 0 so no need to paint anything.
                return;
            }
            // If we have clipBounds available, use them as they will always be
            // smaller than the full layer size.
            x = clipBounds.x;
            y = clipBounds.y;
            width = clipBounds.width;
            height = clipBounds.height;
        } else {
            width = layer.getImage().getWidth();
            height = layer.getImage().getHeight();
        }
        // Create a temporary image to which the color filter will be applied.
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D imageBaseGraphics = (Graphics2D) image.getGraphics();
        // Configure the Graphics2D object with drawing parameters and shader.
        Graphics2D imageGraphics = createCustomGraphics(imageBaseGraphics, paint, compositeOnly, AlphaComposite.SRC_OVER);
        // get a Graphics2D object configured with the drawing parameters, but no shader.
        Graphics2D configuredGraphics = createCustomGraphics(originalGraphics, paint, true, /*compositeOnly*/
        forceMode);
        try {
            // The main draw operation.
            // We translate the operation to take into account that the rendering does not
            // know about the clipping area.
            imageGraphics.translate(-x, -y);
            drawable.draw(imageGraphics, paint);
            // Apply the color filter.
            // Restore the original coordinates system and apply the filter only to the
            // clipped area.
            imageGraphics.translate(x, y);
            filter.applyFilter(imageGraphics, width, height);
            // Draw the tinted image on the main layer using as start point the clipping
            // upper left coordinates.
            configuredGraphics.drawImage(image, x, y, null);
            layer.change();
        } finally {
            // dispose Graphics2D objects
            imageGraphics.dispose();
            imageBaseGraphics.dispose();
            configuredGraphics.dispose();
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) ColorFilter_Delegate(android.graphics.ColorFilter_Delegate) Paint(android.graphics.Paint) 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