@Override public void transformImage(SunGraphics2D sg, BufferedImage img, BufferedImageOp op, int x, int y) { if (op != null) { if (op instanceof AffineTransformOp) { AffineTransformOp atop = (AffineTransformOp) op; transformImage(sg, img, x, y, atop.getTransform(), atop.getInterpolationType()); return; } else { if (D3DBufImgOps.renderImageWithOp(sg, img, op, x, y)) { return; } } img = op.filter(img, null); } copyImage(sg, img, x, y, null); }
public static boolean isSimpleTranslate(SunGraphics2D sg) { int ts = sg.transformState; if (ts <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) { // Integer translates are always "simple" return true; } if (ts >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) { // Scales and beyond are always "not simple" return false; } // non-integer translates are only simple when not interpolating if (sg.interpolationType == AffineTransformOp.TYPE_NEAREST_NEIGHBOR) { return true; } return false; }
public void transformImage(SunGraphics2D sg, BufferedImage img, BufferedImageOp op, int x, int y) { if (op != null) { if (op instanceof AffineTransformOp) { AffineTransformOp atop = (AffineTransformOp) op; transformImage(sg, img, x, y, atop.getTransform(), atop.getInterpolationType()); return; } else { img = op.filter(img, null); } } copyImage(sg, img, x, y, null); }
@Override public void transformImage(SunGraphics2D sg, BufferedImage img, BufferedImageOp op, int x, int y) { if (op != null) { if (op instanceof AffineTransformOp) { AffineTransformOp atop = (AffineTransformOp) op; transformImage(sg, img, x, y, atop.getTransform(), atop.getInterpolationType()); return; } else { if (OGLBufImgOps.renderImageWithOp(sg, img, op, x, y)) { return; } } img = op.filter(img, null); } copyImage(sg, img, x, y, null); }
/** * Rotaciona uma imagem * * @param image imagem a ser rotacionada * @param angle ângulo da rotação * @return imagem rotacionada */ public static ImageIcon girar(ImageIcon image, double angle) { BufferedImage rotateImage = ImageIconToBufferedImage(image); angle %= 360; if (angle < 0) { angle += 360; } AffineTransform tx = new AffineTransform(); tx.rotate(Math.toRadians(angle), rotateImage.getWidth() / 2.0, rotateImage.getHeight() / 2.0); double ytrans; double xtrans; if (angle <= 90) { xtrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getX(); ytrans = tx.transform(new Point2D.Double(0.0, 0.0), null).getY(); } else if (angle <= 180) { xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getX(); ytrans = tx.transform(new Point2D.Double(0, rotateImage.getHeight()), null).getY(); } else if (angle <= 270) { xtrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getX(); ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), rotateImage.getHeight()), null).getY(); } else { xtrans = tx.transform(new Point2D.Double(0, 0), null).getX(); ytrans = tx.transform(new Point2D.Double(rotateImage.getWidth(), 0), null).getY(); } AffineTransform translationTransform = new AffineTransform(); translationTransform.translate(-xtrans, -ytrans); tx.preConcatenate(translationTransform); return new ImageIcon(new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR).filter(rotateImage, null)); }
@Override public BufferedImage run(final @NonNull BufferedImage image) { if (isFlippedHorizontally || isFlippedVertically) { final double scaleX = isFlippedHorizontally ? -1 : 1; final double scaleY = isFlippedVertically ? -1 : 1; final double translateX = isFlippedHorizontally ? -image.getWidth() : 0; final double translateY = isFlippedVertically ? -image.getHeight() : 0; final AffineTransform tx = AffineTransform.getScaleInstance(scaleX, scaleY); tx.translate(translateX, translateY); final BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); return op.filter(image, null); } return image; }
/** * Constructs a new Font. * * @param characterImages * The base character images. * * @param scale * The amount to scale each character image by. * * @throws NullPointerException * If the characterImages is null. * * @throws IOException * If an I/O error occurs. */ public Font(final @NonNull HashMap<Character, BufferedImage> characterImages, final int scale) throws IOException { this.characterImages = characterImages; final int width = characterImages.get('X').getWidth() * scale; final int height = characterImages.get('X').getHeight() * scale; dimensions = new Dimension(width, height); if (scale > 0) { final AffineTransform tx = AffineTransform.getScaleInstance(scale, scale); final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); for (final Map.Entry<Character, BufferedImage> entry : characterImages.entrySet()) { characterImages.put(entry.getKey(), op.filter(entry.getValue(), null)); } } }
/** * Flips and scales the image. * * @return * The flipped and scaled image. */ private BufferedImage applyTransformations() { final AffineTransform tx; if (flipHorizontally && flipVertically) { tx = AffineTransform.getScaleInstance(-scaleX, -scaleY); tx.translate(-image.getWidth(), -image.getHeight()); } else if (flipHorizontally) { tx = AffineTransform.getScaleInstance(-scaleX, scaleY); tx.translate(-image.getWidth(), 0); } else if(flipVertically) { tx = AffineTransform.getScaleInstance(scaleX, -scaleY); tx.translate(0, -image.getHeight()); } else { tx = AffineTransform.getScaleInstance(scaleX, scaleY); } final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); return op.filter(image, null); }
/** * Adds a shadow effect by executing the following steps: 1. Transform visible * pixels to a semi-transparent black 2. Flip the image vertically 3. Scale it * down 4. Render original image and shadow on a buffered image * * @param image * the image * @param xOffset * the x offset * @param yOffset * the y offset * @return the buffered image */ public static BufferedImage addShadow(final BufferedImage image, final int xOffset, final int yOffset) { if (image == null) { return image; } // Transform visible pixels to a semi-transparent black final BufferedImage shadowImage = flashVisiblePixels(image, new Color(0, 0, 0, 30)); if (shadowImage == null) { return image; } final AffineTransform tx = new AffineTransform(); // Flip the image vertically tx.concatenate(AffineTransform.getScaleInstance(1, -0.15)); tx.concatenate(AffineTransform.getTranslateInstance(0, -shadowImage.getHeight())); final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); final BufferedImage rotatedImage = op.filter(shadowImage, null); final BufferedImage shadow = getCompatibleImage(image.getWidth(), image.getHeight() + rotatedImage.getHeight()); final Graphics2D g2D = shadow.createGraphics(); g2D.drawImage(rotatedImage, xOffset, yOffset, null); g2D.drawImage(image, 0, 0, null); g2D.dispose(); return shadow; }
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) { D3DBlitLoops.Blit(src, dst, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, typeval, true); }
/** * Build a scaled version of an image. * * @param img image to scale * @param ratio scaling ratio * @return the scaled image */ public static BufferedImage scale (BufferedImage img, double ratio) { AffineTransform at = AffineTransform.getScaleInstance(ratio, ratio); AffineTransformOp atop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); BufferedImage scaledImg = new BufferedImage( (int) Math.ceil(img.getWidth() * ratio), (int) Math.ceil(img.getHeight() * ratio), img.getType()); return atop.filter(img, scaledImg); }
public static BufferedImage slant(BufferedImage image, FlexQuadrilateral quadrilateral, int xTranslation) { Point p = new Point(quadrilateral.getBottomLeft().x, quadrilateral.getTopLeft().y); double theta = Geometry.theta(quadrilateral.getBottomLeft(), p, quadrilateral.getTopLeft()); AffineTransform transform = AffineTransform.getTranslateInstance(xTranslation, 0); transform.shear(Math.tan(theta), 0); transform.translate(xTranslation, 0); AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(image, null); }
public void affineTransform (double fShxFactor, double fShyFactor) { try { AffineTransform shearer = AffineTransform.getShearInstance (fShxFactor, fShyFactor); AffineTransformOp shear_op = new AffineTransformOp (shearer, null); bufferedImage = shear_op.filter (bufferedImage, null); } catch (Exception e) { System.out.println("Shearing exception = " + e); } }
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) { OGLBlitLoops.Blit(src, dst, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, typeval, true); }
private static BufferedImage scaleSmooth(BufferedImage im, double newWidth, double newHeigth) { int w = im.getWidth(); int h = im.getHeight(); BufferedImage result = new BufferedImage((int)newWidth, (int)newHeigth, BufferedImage.TYPE_INT_ARGB); AffineTransform at = new AffineTransform(); at.scale(newWidth / w, newHeigth / h); AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); result = scaleOp.filter(im, result); return result; }
@Override public void run() { BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB); for (int y = 0; y < display.getHeight(); y++) { for (int x = 0; x < display.getWidth(); x++) { int idx = getIndex(x, y); int nIdx = 3 * idx; int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255 int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255 int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255 int col = (r << 16) | (g << 8) | b; img.setRGB(x, y, col); } } AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -img.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); img = op.filter(img, null); SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); try { ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate))); } catch (IOException ex) { log.warning("can not save Image, Error: " + ex.toString()); } }
@Override public void run() { BufferedImage img = new BufferedImage(display.getWidth(), display.getHeight(), BufferedImage.TYPE_INT_RGB); for (int y = 0; y < display.getHeight(); y++) { for (int x = 0; x < display.getWidth(); x++) { int idx = getIndex(x, y); int nIdx = 3 * idx; int r = ((int) (rgbValues[nIdx++] * 255)); // red component 0...255 int g = ((int) (rgbValues[nIdx++] * 255)); // green component 0...255 int b = ((int) (rgbValues[nIdx] * 255)); // blue component 0...255 int col = (r << 16) | (g << 8) | b; img.setRGB(x, y, col); } } AffineTransform tx = AffineTransform.getScaleInstance(1, -1); //alligns the image correctly tx.translate(0, -img.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); img = op.filter(img, null); SimpleDateFormat sdfDate = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");//dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); try { ImageIO.write(img, "png", new File(String.format("%s/ImageCreator%s.png", path, strDate))); } catch (IOException ex) { log.warning("can not save Image, Error: " + ex.toString()); } }
/** * 缩放图片 * * @param imgPath 源图片绝对路径 * @param disPath 目标图片绝对路径 * @param height 目标高度 * @param width 目标宽度 * @param whiteFill 是否补白 */ public final static void scale(String imgPath, String disPath, int height, int width, boolean whiteFill) { try { double ratio = 0.0; File file = new File(imgPath); BufferedImage bufferedImage = ImageIO.read(file); Image tempImg = bufferedImage.getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH); // 计算比例 if ((bufferedImage.getHeight() > height) || (bufferedImage.getWidth() > width)) { double ratioV = (new Integer(height).doubleValue() / bufferedImage.getHeight()); double ratioH = (new Integer(width).doubleValue() / bufferedImage.getWidth()); ratio = Math.max(ratioV, ratioH); AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(ratio, ratio), null); tempImg = op.filter(bufferedImage, null); } if (whiteFill) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = img.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); if (width == tempImg.getWidth(null)) { g.drawImage(tempImg, 0, (height - tempImg.getHeight(null)) / 2, tempImg.getWidth(null), tempImg.getHeight(null), Color.WHITE, null); } else { g.drawImage(tempImg, (width - tempImg.getWidth(null)) / 2, 0, tempImg.getWidth(null), tempImg.getHeight(null), Color.WHITE, null); } g.dispose(); tempImg = img; } ImageIO.write((BufferedImage)tempImg, "JPEG", new File(disPath)); } catch (IOException e) { // e.printStackTrace(); } }
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) { OGLBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, true); }
public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) { surfaceData = sd; foregroundColor = fg; backgroundColor = bg; transform = new AffineTransform(); stroke = defaultStroke; composite = defaultComposite; paint = foregroundColor; imageComp = CompositeType.SrcOverNoEa; renderHint = SunHints.INTVAL_RENDER_DEFAULT; antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT; fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF; lcdTextContrast = lcdTextContrastDefaultValue; interpolationHint = -1; strokeHint = SunHints.INTVAL_STROKE_DEFAULT; resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT; interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR; validateColor(); devScale = sd.getDefaultScale(); if (devScale != 1) { transform.setToScale(devScale, devScale); invalidateTransform(); } font = f; if (font == null) { font = defaultFont; } setDevClip(sd.getBounds()); invalidatePipe(); }
/** * Sets the preferences for the rendering algorithms. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * @param hints The rendering hints to be set * @see RenderingHints */ public void setRenderingHints(Map<?,?> hints) { this.hints = null; renderHint = SunHints.INTVAL_RENDER_DEFAULT; antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF; textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT; fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF; lcdTextContrast = lcdTextContrastDefaultValue; interpolationHint = -1; interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR; boolean customHintPresent = false; Iterator<?> iter = hints.keySet().iterator(); while (iter.hasNext()) { Object key = iter.next(); if (key == SunHints.KEY_RENDERING || key == SunHints.KEY_ANTIALIASING || key == SunHints.KEY_TEXT_ANTIALIASING || key == SunHints.KEY_FRACTIONALMETRICS || key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST || key == SunHints.KEY_STROKE_CONTROL || key == SunHints.KEY_INTERPOLATION) { setRenderingHint((Key) key, hints.get(key)); } else { customHintPresent = true; } } if (customHintPresent) { this.hints = makeHints(hints); } invalidatePipe(); }
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) { OGLBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, false); }
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) { OGLBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, false); }
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) { OGLBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, true); }
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) { OGLBlitLoops.Blit(src, dst, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, typeval, false); }
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) { D3DBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, true); }
@Override protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) { // punt to the MediaLib-based transformImage() in the superclass if: // - bicubic interpolation is specified // - a background color is specified and will be used // - an appropriate TransformBlit primitive could not be found if (interpType != AffineTransformOp.TYPE_BICUBIC) { SurfaceData dstData = sg.surfaceData; SurfaceData srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, bgColor); if (srcData != null && !isBgOperation(srcData, bgColor)) { SurfaceType srcType = srcData.getSurfaceType(); SurfaceType dstType = dstData.getSurfaceType(); TransformBlit blit = TransformBlit.getFromCache(srcType, sg.imageComp, dstType); if (blit != null) { blit.Transform(srcData, dstData, sg.composite, sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2-sx1, sy2-sy1); return; } } } super.renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor); }
public void Blit(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx, int sy, int dx, int dy, int w, int h) { D3DBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx+w, sy+h, dx, dy, dx+w, dy+h, false); }
public void Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2) { D3DBlitLoops.IsoBlit(src, dst, null, null, comp, clip, null, AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, false); }