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);
}
});
}
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);
}
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();
}
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);
}
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;
}
}
Aggregations