Search in sources :

Example 21 with Graphics2D

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

the class Canvas_Delegate method native_drawBitmap.

@LayoutlibDelegate
public static void native_drawBitmap(long nativeCanvas, int[] colors, int offset, int stride, final float x, final float y, int width, int height, boolean hasAlpha, long nativePaintOrZero) {
    // create a temp BufferedImage containing the content.
    final BufferedImage image = new BufferedImage(width, height, hasAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
    image.setRGB(0, 0, width, height, colors, offset, stride);
    draw(nativeCanvas, nativePaintOrZero, true, /*compositeOnly*/
    false, /*forceSrcMode*/
    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);
            }
            graphics.drawImage(image, (int) x, (int) y, null);
        }
    });
}
Also used : GcSnapshot(com.android.layoutlib.bridge.impl.GcSnapshot) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 22 with Graphics2D

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

the class Canvas_Delegate method nativeDrawBitmapMatrix.

@LayoutlibDelegate
public static void nativeDrawBitmapMatrix(long nCanvas, Bitmap bitmap, long nMatrix, long 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(bitmap);
    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 23 with Graphics2D

use of java.awt.Graphics2D in project screenbird by adamhub.

the class ImageUtil method addMark.

/**
     * Adds a watermark to the image.
     * @param bufferedImage
     * @param markImageSource
     * @param alpha
     * @param mark_position
     * @throws ImageDoesNotExistException
     * @throws IllegalArgumentException
     * @throws IOException 
     */
public static void addMark(BufferedImage bufferedImage, String markImageSource, float alpha, int mark_position) throws ImageDoesNotExistException, IllegalArgumentException, IOException {
    File fileMarkImage = new File(markImageSource);
    if (!fileMarkImage.exists()) {
        throw new ImageDoesNotExistException("Mark Image doesn't exists: " + fileMarkImage.getAbsolutePath());
    }
    int width = bufferedImage.getWidth();
    int height = bufferedImage.getHeight();
    Graphics2D g = bufferedImage.createGraphics();
    g.drawImage(bufferedImage, 0, 0, width, height, null);
    BufferedImage bufferedMarkImage = ImageIO.read(fileMarkImage);
    int mark_img_width = bufferedMarkImage.getWidth();
    int mark_img_height = bufferedMarkImage.getHeight();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
    switch(mark_position) {
        case ImageUtil.MARK_LEFT_TOP:
            g.drawImage(bufferedMarkImage, OFFSET_X, OFFSET_Y, mark_img_width, mark_img_height, null);
            break;
        case ImageUtil.MARK_LEFT_BOTTOM:
            g.drawImage(bufferedMarkImage, OFFSET_X, (height - mark_img_height - OFFSET_Y), mark_img_width, mark_img_height, null);
            break;
        case ImageUtil.MARK_CENTER:
            g.drawImage(bufferedMarkImage, (width - mark_img_width - OFFSET_X) / 2, (height - mark_img_height - OFFSET_Y) / 2, mark_img_width, mark_img_height, null);
            break;
        case ImageUtil.MARK_RIGHT_TOP:
            g.drawImage(bufferedMarkImage, (width - mark_img_width - OFFSET_X), OFFSET_Y, mark_img_width, mark_img_height, null);
            break;
        case ImageUtil.MARK_RIGHT_BOTTOM:
        default:
            g.drawImage(bufferedMarkImage, (width - mark_img_width - OFFSET_X), (height - mark_img_height - OFFSET_Y), mark_img_width, mark_img_height, null);
    }
    g.dispose();
}
Also used : File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 24 with Graphics2D

use of java.awt.Graphics2D in project ACS by ACS-Community.

the class LogoPanel method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    try {
        int w = getWidth();
        int h = getHeight();
        // optimization: reuse GradientPaint if possible
        if (gradientPaint == null || w != oldW || h != oldH) {
            gradientPaint = new GradientPaint(0, 0, startcolor, w, h, endcolor, false);
            oldW = w;
            oldH = h;
        }
        Graphics2D g2 = (Graphics2D) g;
        g2.setPaint(gradientPaint);
        g2.fillRect(0, 0, w, h);
    } catch (InternalError exc) {
    // sometimes (but rarely), there's an error in g2.fillRect():
    /* java.lang.InternalError: MaskFill can only fill with colors
             *        at sun.java2d.loops.MaskFill.makePrimitive(MaskFill.java:120)
             */
    }
    super.paintComponent(g);
}
Also used : GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 25 with Graphics2D

use of java.awt.Graphics2D in project ACS by ACS-Community.

the class PrintableComponent method print.

//
// -- implements Printable ----------------------------------------------
//
/* (non-Javadoc)
   * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
   */
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex == 0) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
        double pageHeight = pageFormat.getImageableHeight();
        double pageWidth = pageFormat.getImageableWidth();
        double width = (double) component.getWidth();
        double height = (double) component.getHeight();
        double xScale = 1;
        if (width >= pageWidth) {
            xScale = pageWidth / width;
        }
        double yScale = 1;
        if (height >= pageHeight) {
            yScale = pageHeight / height;
        }
        g2d.scale(xScale, yScale);
        component.paint(g2d);
        return Printable.PAGE_EXISTS;
    } else {
        return Printable.NO_SUCH_PAGE;
    }
}
Also used : 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