/** * Get scaled image. */ public synchronized BufferedImage getAsBitmapForSize( int width, int height ) { String key = width + "x" + height; BufferedImage result = cache.get( key ); if ( result == null ) { result = createBitmap( width, height ); renderSimple( result ); cache.put( key, result ); } return result; }
public synchronized void drawToGraphics( Graphics2D gc, int centerX, int centerY, int width, int height, double angleRadians ) { render( gc, centerX, centerY, width, height, angleRadians ); }
/** * Draw rotated image on double canvas size. It required against lost corners on rotate. */ public synchronized BufferedImage getAsBitmapForSize( int width, int height, double angleRadians ) { int angleDegree = (int) Math.round( Math.toDegrees( angleRadians ) ); while ( angleDegree < 0 ) { angleDegree += 360; } angleDegree %= 360; angleRadians = Math.toRadians( angleDegree ); String key = width + "x" + height + "/" + Integer.toString( angleDegree ); BufferedImage result = cache.get( key ); if ( result == null ) { result = createDoubleBitmap( width, height ); Graphics2D gc = createGraphics( result ); render( gc, result.getWidth() / 2, result.getHeight() / 2, width, height, angleRadians ); gc.dispose(); cache.put( key, result ); } return result; }
private void drawImage( SwingUniversalImage img, int centerX, int centerY, double angle, int imageSize ) { if ( isDrawingPixelatedImages() && img.isBitmap() ) { BufferedImage bi = img.getAsBitmapForSize( imageSize, imageSize, angle ); int offx = centerX + xOffset - bi.getWidth() / 2; int offy = centerY + yOffset - bi.getHeight() / 2; for ( int x = 0; x < bi.getWidth( observer ); x++ ) { for ( int y = 0; y < bi.getHeight( observer ); y++ ) { int rgb = bi.getRGB( x, y ); gc.setColor( new Color( rgb ) ); gc.setStroke( new BasicStroke( 1.0f ) ); gc.drawLine( offx + x, offy + y, offx + x, offy + y ); } } } else { gc.setBackground( Color.white ); gc.clearRect( centerX, centerY, imageSize, imageSize ); img.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle ); } }
@Override protected Image renderRotated( Device device, int width, int height, double angleRadians ) { BufferedImage doubleArea = SwingUniversalImage.createDoubleBitmap( width, height ); Graphics2D gc = SwingUniversalImage.createGraphics( doubleArea ); SwingUniversalImageSvg.render( gc, svgGraphicsNode, svgGraphicsSize, doubleArea.getWidth() / 2, doubleArea .getHeight() / 2, width, height, angleRadians ); gc.dispose(); return swing2swt( device, doubleArea ); } }
@Override protected Image renderSimple( Device device, int width, int height ) { BufferedImage area = SwingUniversalImage.createBitmap( width, height ); Graphics2D gc = SwingUniversalImage.createGraphics( area ); SwingUniversalImageSvg.render( gc, svgGraphicsNode, svgGraphicsSize, width / 2, height / 2, width, height, 0 ); gc.dispose(); return swing2swt( device, area ); }
private void drawImage( SwingUniversalImage img, int locationX, int locationY, int imageSize ) { if ( isDrawingPixelatedImages() && img.isBitmap() ) { BufferedImage bi = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB ); Graphics2D g2 = (Graphics2D) bi.getGraphics(); g2.setColor( Color.WHITE ); g2.fillRect( 0, 0, imageSize, imageSize ); g2.drawImage( img.getAsBitmapForSize( imageSize, imageSize ), 0, 0, observer ); g2.dispose(); for ( int x = 0; x < bi.getWidth( observer ); x++ ) { for ( int y = 0; y < bi.getHeight( observer ); y++ ) { int rgb = bi.getRGB( x, y ); gc.setColor( new Color( rgb ) ); gc.setStroke( new BasicStroke( 1.0f ) ); gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x, locationY + yOffset + y ); } } } else { gc.setBackground( Color.white ); gc.clearRect( locationX, locationY, imageSize, imageSize ); img.drawToGraphics( gc, locationX, locationY, imageSize, imageSize ); } }
private void drawImage( SwingUniversalImage image, int locationX, int locationY, int imageSize ) { if ( isDrawingPixelatedImages() && image.isBitmap() ) { BufferedImage img = image.getAsBitmapForSize( imageSize, imageSize ); ColorModel cm = img.getColorModel(); Raster raster = img.getRaster(); for ( int x = 0; x < img.getWidth( observer ); x++ ) { for ( int y = 0; y < img.getHeight( observer ); y++ ) { Object pix = raster.getDataElements( x, y, null ); gc.setColor( new Color( cm.getRed( pix ), cm.getGreen( pix ), cm.getBlue( pix ), cm.getAlpha( pix ) ) ); gc.setStroke( new BasicStroke( 1.0f ) ); gc.drawLine( locationX + xOffset + x, locationY + yOffset + y, locationX + xOffset + x + 1, locationY + yOffset + y + 1 ); } } } else { image.drawToGraphics( gc, locationX, locationY, imageSize, imageSize ); } }
public synchronized void drawToGraphics( Graphics2D gc, int locationX, int locationY, int width, int height ) { render( gc, locationX + width / 2, locationY + height / 2, width, height, 0 ); }
private void drawImage( SwingUniversalImage image, int centerX, int centerY, double angle, int imageSize ) { if ( isDrawingPixelatedImages() && image.isBitmap() ) { BufferedImage img = image.getAsBitmapForSize( imageSize, imageSize, angle ); ColorModel cm = img.getColorModel(); Raster raster = img.getRaster(); int offx = centerX + xOffset - img.getWidth() / 2; int offy = centerY + yOffset - img.getHeight() / 2; for ( int x = 0; x < img.getWidth( observer ); x++ ) { for ( int y = 0; y < img.getHeight( observer ); y++ ) { Object pix = raster.getDataElements( x, y, null ); gc.setColor( new Color( cm.getRed( pix ), cm.getGreen( pix ), cm.getBlue( pix ), cm.getAlpha( pix ) ) ); gc.setStroke( new BasicStroke( 1.0f ) ); gc.drawLine( offx + x, offy + y, offx + x + 1, offy + y + 1 ); } } } else { image.drawToGraphics( gc, centerX, centerY, imageSize, imageSize, angle ); } }