List of usage examples for java.awt.geom AffineTransform scale
@SuppressWarnings("fallthrough") public void scale(double sx, double sy)
From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java
/** * process : BI : begin inline image./*w w w.j a v a2s . com*/ * @param operator The operator that is being executed. * @param arguments List * @throws java.io.IOException If there is an error displaying the inline image. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; PDPage page = drawer.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { log.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); drawer.drawImage(awtImage, at); }
From source file:ImageOps.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; g2.setColor(Color.black);//from w w w. ja v a 2 s . co m float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 }; String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" }; for (int i = 0; i < bi.length; i++) { int iw = bi[i].getWidth(this); int ih = bi[i].getHeight(this); int x = 0, y = 0; AffineTransform at = new AffineTransform(); at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih); BufferedImageOp biop = null; BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); switch (i) { case 0: case 1: x = i == 0 ? 5 : w / 2 + 3; y = 15; Kernel kernel = new Kernel(3, 3, data[i]); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); break; case 2: x = 5; y = h / 2 + 15; byte chlut[] = new byte[256]; for (int j = 0; j < 200; j++) chlut[j] = (byte) (256 - j); ByteLookupTable blut = new ByteLookupTable(0, chlut); LookupOp lop = new LookupOp(blut, null); lop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); break; case 3: x = w / 2 + 3; y = h / 2 + 15; RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); rop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); } g2.drawImage(bimg, biop, x, y); TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext()); tl.draw(g2, (float) x, (float) y - 4); } }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.BeginInlineImage.java
/** * process : BI : begin inline image./*from w w w .j a va 2 s. c o m*/ * * @param operator The operator that is being executed. * @param arguments List * @throws IOException If there is an error displaying the inline image. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); if (params.isStencil()) { //TODO implement inline image stencil masks LOG.warn("Stencil masks are not implemented, background may be incorrect"); } BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { LOG.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); extractor.drawImage(awtImage, at); }
From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * @param operator The operator that is being executed. * @param arguments List/*from w w w . ja va 2 s . c om*/ * @throws java.io.IOException If there is an error invoking the sub object. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context; PDPage page = drawer.getPage(); COSName objectName = (COSName) arguments.get(0); Map xobjects = drawer.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { log.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { image.setGraphicsState(drawer.getGraphicsState()); BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { log.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); log.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) angle = (-1) * angle; ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); drawer.drawImage(awtImage, ctmAT); } catch (Exception e) { e.printStackTrace(); log.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream invoke = (COSStream) form.getCOSObject(); PDResources pdResources = form.getResources(); if (pdResources == null) { pdResources = page.findResources(); } // if there is an optional form matrix, we have to // map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } getContext().processSubStream(page, pdResources, invoke); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:org.apache.fop.render.pcl.PCLGraphics2DAdapter.java
/** {@inheritDoc} */ public void paintImage(Graphics2DImagePainter painter, RendererContext context, int x, int y, int width, int height) throws IOException { PCLRendererContext pclContext = PCLRendererContext.wrapRendererContext(context); PCLRenderer pcl = (PCLRenderer) context.getRenderer(); PCLGenerator gen = pcl.gen;/*www . jav a2 s . c o m*/ // get the 'width' and 'height' attributes of the image/document Dimension dim = painter.getImageSize(); float imw = (float) dim.getWidth(); float imh = (float) dim.getHeight(); boolean painted = false; boolean paintAsBitmap = pclContext.paintAsBitmap(); if (!paintAsBitmap) { ByteArrayOutputStream baout = new ByteArrayOutputStream(); PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution()); try { GraphicContext ctx = (GraphicContext) pcl.getGraphicContext().clone(); AffineTransform prepareHPGL2 = new AffineTransform(); prepareHPGL2.scale(0.001, 0.001); ctx.setTransform(prepareHPGL2); PCLGraphics2D graphics = new PCLGraphics2D(tempGen); graphics.setGraphicContext(ctx); graphics.setClippingDisabled(pclContext.isClippingDisabled()); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh); painter.paint(graphics, area); //If we arrive here, the graphic is natively paintable, so write the graphic pcl.saveGraphicsState(); pcl.setCursorPos(x, y); gen.writeCommand( "*c" + gen.formatDouble4(width / 100f) + "x" + gen.formatDouble4(height / 100f) + "Y"); gen.writeCommand("*c0T"); gen.enterHPGL2Mode(false); gen.writeText("\nIN;"); gen.writeText("SP1;"); //One Plotter unit is 0.025mm! double scale = imw / UnitConv.mm2pt(imw * 0.025); gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;"); gen.writeText("IR0,100,0,100;"); gen.writeText("PU;PA0,0;\n"); baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream gen.writeText("\n"); gen.enterPCLMode(false); pcl.restoreGraphicsState(); painted = true; } catch (UnsupportedOperationException uoe) { log.debug("Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage()); } } if (!painted) { //Fallback solution: Paint to a BufferedImage int resolution = Math.round(context.getUserAgent().getTargetResolution()); BufferedImage bi = paintToBufferedImage(painter, pclContext, resolution, !pclContext.isColorCanvas(), false); pcl.setCursorPos(x, y); gen.paintBitmap(bi, new Dimension(width, height), pclContext.isSourceTransparency()); } }
From source file:org.apache.pdfbox.util.operator.pagedrawer.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * @param operator The operator that is being executed. * @param arguments List//from w w w .j av a 2s .c o m * @throws IOException If there is an error invoking the sub object. */ public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { PageDrawer drawer = (PageDrawer) context; PDPage page = drawer.getPage(); COSName objectName = (COSName) arguments.get(0); Map<String, PDXObject> xobjects = drawer.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { LOG.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { if (image.getImageMask()) { // set the current non stroking colorstate, so that it can // be used to create a stencil masked image image.setStencilColor(drawer.getGraphicsState().getNonStrokingColor()); } BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { LOG.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = drawer.getPageSize().getHeight(); LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) { angle = (-1) * angle; } ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); drawer.drawImage(awtImage, ctmAT); } catch (Exception e) { e.printStackTrace(); LOG.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream invoke = (COSStream) form.getCOSObject(); PDResources pdResources = form.getResources(); if (pdResources == null) { pdResources = page.findResources(); } // if there is an optional form matrix, we have to // map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } getContext().processSubStream(page, pdResources, invoke); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:org.apache.fop.render.pcl.PCLImageHandlerGraphics2D.java
/** {@inheritDoc} */ public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException { PCLRenderingContext pclContext = (PCLRenderingContext) context; ImageGraphics2D imageG2D = (ImageGraphics2D) image; Dimension imageDim = imageG2D.getSize().getDimensionMpt(); PCLGenerator gen = pclContext.getPCLGenerator(); Point2D transPoint = pclContext.transformedPoint(pos.x, pos.y); gen.setCursorPos(transPoint.getX(), transPoint.getY()); boolean painted = false; ByteArrayOutputStream baout = new ByteArrayOutputStream(); PCLGenerator tempGen = new PCLGenerator(baout, gen.getMaximumBitmapResolution()); tempGen.setDitheringQuality(gen.getDitheringQuality()); try {//from w w w. j ava2 s . c o m GraphicContext ctx = (GraphicContext) pclContext.getGraphicContext().clone(); AffineTransform prepareHPGL2 = new AffineTransform(); prepareHPGL2.scale(0.001, 0.001); ctx.setTransform(prepareHPGL2); PCLGraphics2D graphics = new PCLGraphics2D(tempGen); graphics.setGraphicContext(ctx); graphics.setClippingDisabled(false /*pclContext.isClippingDisabled()*/); Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imageDim.getWidth(), imageDim.getHeight()); imageG2D.getGraphics2DImagePainter().paint(graphics, area); //If we arrive here, the graphic is natively paintable, so write the graphic gen.writeCommand( "*c" + gen.formatDouble4(pos.width / 100f) + "x" + gen.formatDouble4(pos.height / 100f) + "Y"); gen.writeCommand("*c0T"); gen.enterHPGL2Mode(false); gen.writeText("\nIN;"); gen.writeText("SP1;"); //One Plotter unit is 0.025mm! double scale = imageDim.getWidth() / UnitConv.mm2pt(imageDim.getWidth() * 0.025); gen.writeText("SC0," + gen.formatDouble4(scale) + ",0,-" + gen.formatDouble4(scale) + ",2;"); gen.writeText("IR0,100,0,100;"); gen.writeText("PU;PA0,0;\n"); baout.writeTo(gen.getOutputStream()); //Buffer is written to output stream gen.writeText("\n"); gen.enterPCLMode(false); painted = true; } catch (UnsupportedOperationException uoe) { log.debug( "Cannot paint graphic natively. Falling back to bitmap painting. Reason: " + uoe.getMessage()); } if (!painted) { //Fallback solution: Paint to a BufferedImage FOUserAgent ua = context.getUserAgent(); ImageManager imageManager = ua.getFactory().getImageManager(); ImageRendered imgRend; try { imgRend = (ImageRendered) imageManager.convertImage(imageG2D, new ImageFlavor[] { ImageFlavor.RENDERED_IMAGE }/*, hints*/); } catch (ImageException e) { throw new IOException("Image conversion error while converting the image to a bitmap" + " as a fallback measure: " + e.getMessage()); } gen.paintBitmap(imgRend.getRenderedImage(), new Dimension(pos.width, pos.height), pclContext.isSourceTransparencyEnabled()); } }
From source file:Paints.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Paint the entire background using a GradientPaint. // The background color varies diagonally from deep red to pale blue g.setPaint(new GradientPaint(0, 0, new Color(150, 0, 0), WIDTH, HEIGHT, new Color(200, 200, 255))); g.fillRect(0, 0, WIDTH, HEIGHT); // fill the background // Use a different GradientPaint to draw a box. // This one alternates between deep opaque green and transparent green. // Note: the 4th arg to Color() constructor specifies color opacity g.setPaint(new GradientPaint(0, 0, new Color(0, 150, 0), 20, 20, new Color(0, 150, 0, 0), true)); g.setStroke(new BasicStroke(15)); // use wide lines g.drawRect(25, 25, WIDTH - 50, HEIGHT - 50); // draw the box // The glyphs of fonts can be used as Shape objects, which enables // us to use Java2D techniques with letters Just as we would with // any other shape. Here we get some letter shapes to draw. Font font = new Font("Serif", Font.BOLD, 10); // a basic font Font bigfont = // a scaled up version font.deriveFont(AffineTransform.getScaleInstance(30.0, 30.0)); GlyphVector gv = bigfont.createGlyphVector(g.getFontRenderContext(), "JAV"); Shape jshape = gv.getGlyphOutline(0); // Shape of letter J Shape ashape = gv.getGlyphOutline(1); // Shape of letter A Shape vshape = gv.getGlyphOutline(2); // Shape of letter V // We're going to outline the letters with a 5-pixel wide line g.setStroke(new BasicStroke(5.0f)); // We're going to fake shadows for the letters using the // following Paint and AffineTransform objects Paint shadowPaint = new Color(0, 0, 0, 100); // Translucent black AffineTransform shadowTransform = AffineTransform.getShearInstance(-1.0, 0.0); // Shear to the right shadowTransform.scale(1.0, 0.5); // Scale height by 1/2 // Move to the baseline of our first letter g.translate(65, 270);//from www .ja v a 2s . c om // Draw the shadow of the J shape g.setPaint(shadowPaint); g.translate(15, 20); // Compensate for the descender of the J // transform the J into the shape of its shadow, and fill it g.fill(shadowTransform.createTransformedShape(jshape)); g.translate(-15, -20); // Undo the translation above // Now fill the J shape with a solid (and opaque) color g.setPaint(Color.blue); // Fill with solid, opaque blue g.fill(jshape); // Fill the shape g.setPaint(Color.black); // Switch to solid black g.draw(jshape); // And draw the outline of the J // Now draw the A shadow g.translate(75, 0); // Move to the right g.setPaint(shadowPaint); // Set shadow color g.fill(shadowTransform.createTransformedShape(ashape)); // draw shadow // Draw the A shape using a solid transparent color g.setPaint(new Color(0, 255, 0, 125)); // Transparent green as paint g.fill(ashape); // Fill the shape g.setPaint(Color.black); // Switch to solid back g.draw(ashape); // Draw the outline // Move to the right and draw the shadow of the letter V g.translate(175, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(vshape)); // We're going to fill the next letter using a TexturePaint, which // repeatedly tiles an image. The first step is to obtain the image. // We could load it from an image file, but here we create it // ourselves by drawing a into an off-screen image. Note that we use // a GradientPaint to fill the off-screen image, so the fill pattern // combines features of both Paint classes. BufferedImage tile = // Create an image new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB); Graphics2D tg = tile.createGraphics(); // Get its Graphics for drawing tg.setColor(Color.pink); tg.fillRect(0, 0, 50, 50); // Fill tile background with pink tg.setPaint(new GradientPaint(40, 0, Color.green, // diagonal gradient 0, 40, Color.gray)); // green to gray tg.fillOval(5, 5, 40, 40); // Draw a circle with this gradient // Use this new tile to create a TexturePaint and fill the letter V g.setPaint(new TexturePaint(tile, new Rectangle(0, 0, 50, 50))); g.fill(vshape); // Fill letter shape g.setPaint(Color.black); // Switch to solid black g.draw(vshape); // Draw outline of letter // Move to the right and draw the shadow of the final A g.translate(160, 0); g.setPaint(shadowPaint); g.fill(shadowTransform.createTransformedShape(ashape)); g.fill(ashape); // Fill letter A g.setPaint(Color.black); // Revert to solid black g.draw(ashape); // Draw the outline of the A }
From source file:BufferedImageThread.java
public void paintComponent(Graphics g) { super.paintComponent(g); Dimension d = getSize();//from w w w . j a v a2 s . c om bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); step(d.width, d.height); AffineTransform at = new AffineTransform(); at.setToIdentity(); at.translate(x, y); at.rotate(Math.toRadians(rotate)); at.scale(scale, scale); big.drawImage(image, at, this); Graphics2D g2D = (Graphics2D) g; g2D.drawImage(bi, 0, 0, null); big.dispose(); }
From source file:MainClass.java
public void paintToPDF(JTextPane ta) { try {/*from w w w . j a v a2 s.c o m*/ ta.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60)); Document document = new Document(); FileOutputStream fos = new FileOutputStream("2.pdf"); PdfWriter writer = PdfWriter.getInstance(document, fos); document.setPageSize(new com.lowagie.text.Rectangle(612, 792)); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.concatCTM(1, 0, 0, 1, 0, 0); DefaultFontMapper mapper = new DefaultFontMapper(); mapper.insertDirectory("c:/windows/fonts"); Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f); AffineTransform at = new AffineTransform(); at.translate(convertToPixels(20), convertToPixels(20)); at.scale(pixelToPoint, pixelToPoint); g2.transform(at); g2.setColor(Color.WHITE); g2.fill(ta.getBounds()); Rectangle alloc = getVisibleEditorRect(ta); ta.getUI().getRootView(ta).paint(g2, alloc); g2.setColor(Color.BLACK); g2.draw(ta.getBounds()); g2.dispose(); cb.restoreState(); document.close(); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }