Search in sources :

Example 16 with BufferedImage

use of java.awt.image.BufferedImage in project android_frameworks_base by ParanoidAndroid.

the class NinePatch_Delegate method draw.

// ---- Private Helper methods ----
private static void draw(int canvas_instance, final int left, final int top, final int right, final int bottom, int bitmap_instance, byte[] c, int paint_instance_or_null, final int destDensity, final int srcDensity) {
    // get the delegate from the native int.
    final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance);
    if (bitmap_delegate == null) {
        return;
    }
    if (c == null) {
        // not a 9-patch?
        BufferedImage image = bitmap_delegate.getImage();
        Canvas_Delegate.native_drawBitmap(canvas_instance, bitmap_instance, new Rect(0, 0, image.getWidth(), image.getHeight()), new Rect(left, top, right, bottom), paint_instance_or_null, destDensity, srcDensity);
        return;
    }
    final NinePatchChunk chunkObject = getChunk(c);
    assert chunkObject != null;
    if (chunkObject == null) {
        return;
    }
    Canvas_Delegate canvas_delegate = Canvas_Delegate.getDelegate(canvas_instance);
    if (canvas_delegate == null) {
        return;
    }
    // this one can be null
    Paint_Delegate paint_delegate = Paint_Delegate.getDelegate(paint_instance_or_null);
    canvas_delegate.getSnapshot().draw(new GcSnapshot.Drawable() {

        @Override
        public void draw(Graphics2D graphics, Paint_Delegate paint) {
            chunkObject.draw(bitmap_delegate.getImage(), graphics, left, top, right - left, bottom - top, destDensity, srcDensity);
        }
    }, paint_delegate, true, /*compositeOnly*/
    false);
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) NinePatchChunk(com.android.ninepatch.NinePatchChunk) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 17 with BufferedImage

use of java.awt.image.BufferedImage 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 18 with BufferedImage

use of java.awt.image.BufferedImage 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 19 with BufferedImage

use of java.awt.image.BufferedImage in project android_frameworks_base by ParanoidAndroid.

the class Canvas_Delegate method native_drawBitmap.

@LayoutlibDelegate
static /*package*/
void native_drawBitmap(Canvas thisCanvas, int nativeCanvas, int bitmap, float left, float top, int nativePaintOrZero, int canvasDensity, int screenDensity, int bitmapDensity) {
    // get the delegate from the native int.
    Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
    if (bitmapDelegate == null) {
        return;
    }
    BufferedImage image = bitmapDelegate.getImage();
    float right = left + image.getWidth();
    float bottom = top + image.getHeight();
    drawBitmap(nativeCanvas, bitmapDelegate, nativePaintOrZero, 0, 0, image.getWidth(), image.getHeight(), (int) left, (int) top, (int) right, (int) bottom);
}
Also used : BufferedImage(java.awt.image.BufferedImage) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 20 with BufferedImage

use of java.awt.image.BufferedImage in project android_frameworks_base by ParanoidAndroid.

the class Canvas_Delegate method native_drawBitmap.

@LayoutlibDelegate
static /*package*/
void native_drawBitmap(int nativeCanvas, int bitmap, Rect src, Rect dst, int nativePaintOrZero, int screenDensity, int bitmapDensity) {
    // get the delegate from the native int.
    Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap);
    if (bitmapDelegate == null) {
        return;
    }
    BufferedImage image = bitmapDelegate.getImage();
    if (src == null) {
        drawBitmap(nativeCanvas, bitmapDelegate, nativePaintOrZero, 0, 0, image.getWidth(), image.getHeight(), dst.left, dst.top, dst.right, dst.bottom);
    } else {
        drawBitmap(nativeCanvas, bitmapDelegate, nativePaintOrZero, src.left, src.top, src.width(), src.height(), dst.left, dst.top, dst.right, dst.bottom);
    }
}
Also used : BufferedImage(java.awt.image.BufferedImage) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1364 Graphics2D (java.awt.Graphics2D)335 IOException (java.io.IOException)186 File (java.io.File)164 Graphics (java.awt.Graphics)91 ByteArrayInputStream (java.io.ByteArrayInputStream)80 Color (java.awt.Color)74 ByteArrayOutputStream (java.io.ByteArrayOutputStream)74 Test (org.junit.Test)72 WritableRaster (java.awt.image.WritableRaster)65 Rectangle (java.awt.Rectangle)60 AffineTransform (java.awt.geom.AffineTransform)52 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)46 InputStream (java.io.InputStream)46 Image (java.awt.Image)43 Dimension (java.awt.Dimension)42 ImageWriter (javax.imageio.ImageWriter)40 Point (java.awt.Point)36 ArrayList (java.util.ArrayList)36 ImageIcon (javax.swing.ImageIcon)35