@Signature public PImage rotate(double angle) { double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle))); int w = image.getWidth(null), h = image.getHeight(null); int neww = (int) Math.floor(w*cos + h*sin), newh = (int) Math.floor(h*cos + w*sin); BufferedImage bimg = new BufferedImage(neww, newh, image.getType()); Graphics2D g = bimg.createGraphics(); g.translate((neww-w)/2, (newh-h)/2); g.rotate(Math.toRadians(angle), w/2, h/2); g.drawRenderedImage(image, null); g.dispose(); this.image = bimg; return this; }
private BufferedImage scale(BufferedImage source,double ratio) { int w = (int) (source.getWidth() * ratio); int h = (int) (source.getHeight() * ratio); BufferedImage bi = getCompatibleImage(w, h); Graphics2D g2d = bi.createGraphics(); double xScale = (double) w / source.getWidth(); double yScale = (double) h / source.getHeight(); AffineTransform at = AffineTransform.getScaleInstance(xScale,yScale); g2d.drawRenderedImage(source, at); g2d.dispose(); return bi; } private BufferedImage getCompatibleImage(int w, int h) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage image = gc.createCompatibleImage(w, h); return image; }
graphics.drawRenderedImage(img, at); graphics.setClip(clipOld);
g.drawRenderedImage( avatar, scale ); Log.debug( "Resized image is {}x{}.", resizedAvatar.getWidth(), resizedAvatar.getHeight() );
g.translate((neww-w)/2, (newh-h)/2); g.rotate(Math.toRadians(amount), w/2, h/2); g.drawRenderedImage(src, null); g.dispose(); origDst = dst;
@Override public void drawRenderedImage(RenderedImage img, AffineTransform xform) { groupG2D.drawRenderedImage(img, xform); alphaG2D.drawRenderedImage(img, xform); }
public void drawRenderedImage(RenderedImage img, AffineTransform xform) { delegate.drawRenderedImage(img, xform); }
/** * scale image * * @param sbi image to scale * @param imageType type of image * @param dWidth width of destination image * @param dHeight height of destination image * @param fWidth x-factor for transformation / scaling * @param fHeight y-factor for transformation / scaling * @return scaled image */ public static BufferedImage scale(BufferedImage sbi, int imageType, int dWidth, int dHeight, double fWidth, double fHeight) { BufferedImage dbi = null; if(sbi != null) { dbi = new BufferedImage(dWidth, dHeight, imageType); Graphics2D g = dbi.createGraphics(); AffineTransform at = AffineTransform.getScaleInstance(fWidth, fHeight); g.drawRenderedImage(sbi, at); } return dbi; }
private static BufferedImage rotateImage(BufferedImage image, double angle) { double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int width = image.getWidth(), height = image.getHeight(); int newWidth = (int) Math.floor(width * cos + height * sin), newHeight = (int) Math.floor(height * cos + width * sin); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); BufferedImage result = gc.createCompatibleImage(newWidth, newHeight, Transparency.TRANSLUCENT); Graphics2D g = result.createGraphics(); g.translate((newWidth - width) / 2, (newHeight - height) / 2); g.rotate(angle, width / 2, height / 2); g.drawRenderedImage(image, null); g.dispose(); return result; }
/** * Rotates an image. Actually rotates a new copy of the image. * * @param img The image to be rotated * @param angle The angle in degrees * @return The rotated image */ public static Image rotate(Image img, double angle) { double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle))); int w = img.getWidth(null), h = img.getHeight(null); int neww = (int) Math.floor(w*cos + h*sin), newh = (int) Math.floor(h*cos + w*sin); BufferedImage bimg = toBufferedImage(getEmptyImage(neww, newh)); Graphics2D g = bimg.createGraphics(); g.translate((neww-w)/2, (newh-h)/2); g.rotate(Math.toRadians(angle), w/2, h/2); g.drawRenderedImage(toBufferedImage(img), null); g.dispose(); return toImage(bimg); }
public static BufferedImage rotate(BufferedImage image, double angle) { double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle)); int w = image.getWidth(), h = image.getHeight(); int neww = (int)Math.floor(w*cos+h*sin), newh = (int) Math.floor(h * cos + w * sin); GraphicsConfiguration gc = getDefaultConfiguration(); BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT); Graphics2D g = result.createGraphics(); g.translate((neww - w) / 2, (newh - h) / 2); g.rotate(angle, w / 2, h / 2); g.drawRenderedImage(image, null); g.dispose(); return result; } private static GraphicsConfiguration getDefaultConfiguration() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); return gd.getDefaultConfiguration(); }
@Override public void drawBitmap(Bitmap bitmap, Matrix matrix) { this.graphics2D.drawRenderedImage(AwtGraphicFactory.getBitmap(bitmap), AwtGraphicFactory.getAffineTransform(matrix)); }
try { g.setComposite(AlphaComposite.Src); g.drawRenderedImage(pOriginal, IDENTITY_TRANSFORM);
private BufferedImage blend(BufferedImage src, BufferedImage dst) { BufferedImage blend = new BufferedImage(src.getWidth(), dst.getWidth(), src.getType()); Graphics2D graphics = (Graphics2D) blend.getGraphics(); graphics.drawRenderedImage(src, new AffineTransform()); graphics.setComposite(composite); graphics.drawRenderedImage(dst, new AffineTransform()); graphics.dispose(); return blend; }
private BufferedImage convertImage(BufferedImage src, int imageType) { BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), imageType); Graphics2D graphics = (Graphics2D) result.getGraphics(); graphics.drawRenderedImage(src, new AffineTransform()); graphics.dispose(); return result; } }
graphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics.drawRenderedImage(image, markAT); } finally { graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, interpolation);
(int) Math.round(tileRect.right - (int) tileRect.left), (int) Math.round(tileRect.bottom) - (int) Math.round(tileRect.top) // subtract in after rounding to get same error as on neighbor tile ); this.graphics2D.drawRenderedImage(bufferedImage, transform); this.graphics2D.setClip(null);
@Override public void drawBitmap(Bitmap bitmap, Matrix matrix, Filter filter) { this.graphics2D.drawRenderedImage(applyFilter(AwtGraphicFactory.getBitmap(bitmap), filter), AwtGraphicFactory.getAffineTransform(matrix)); }
public void draw(Graphics2D g) { setupTransform(g); // You can only position an image using an affine transformation. // We use the transformation to translate the image to the specified // position, and scale it according to the given width and height. Transform imageTrans = new Transform(); // Move to the image position. Convert x, y, which are centered coordinates, // to "real" coordinates. double factor = getScaleFactor(); double finalWidth = image.getWidth() * factor; double finalHeight = image.getHeight() * factor; imageTrans.translate(x - finalWidth / 2, y - finalHeight / 2); // Scaling only applies to image that have their desired width and/or height set. // However, getScaleFactor return 1 if height/width are not set, in effect negating // the effect of the scale. imageTrans.scale(getScaleFactor()); double a = clamp(alpha); Composite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) a); Composite oldComposite = g.getComposite(); g.setComposite(composite); g.drawRenderedImage(image, imageTrans.getAffineTransform()); g.setComposite(oldComposite); restoreTransform(g); }
translate = true; graphics.drawRenderedImage(applyImage, transform); int numBands = composedImage.getSampleModel().getNumBands(); GridSampleDimension[] sd = new GridSampleDimension[numBands];