List of usage examples for java.awt RenderingHints RenderingHints
public RenderingHints(Key key, Object value)
From source file:test.unit.be.fedict.eid.applet.service.KmlGeneratorTest.java
@Test public void identityWithAddressAndPhotoKml() throws Exception { // setup//from ww w. j a v a 2s . c o m Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateKml(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.PdfGeneratorTest.java
@Test public void identityWithAddressAndPhotoPdf() throws Exception { // setup// w w w. j av a2s.co m Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generatePdf(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:test.unit.be.fedict.eid.applet.service.VcardGeneratorTest.java
@Test public void identityWithAddressAndPhotoVcard() throws Exception { // setup/* www . j av a 2 s . co m*/ Identity identity = new Identity(); identity.name = "Test Name"; identity.firstName = "Test First name"; identity.dateOfBirth = new GregorianCalendar(); identity.gender = Gender.MALE; Address address = new Address(); address.streetAndNumber = "Test Street 1A"; address.zip = "1234"; address.municipality = "Test Municipality"; BufferedImage image = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setRenderingHints(renderingHints); graphics.setColor(Color.WHITE); graphics.fillRect(1, 1, 140 - 1 - 1, 200 - 1 - 1); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.setColor(Color.BLACK); graphics.drawString("Test Photo", 0, 200 / 2); graphics.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "jpg", baos); byte[] photo = baos.toByteArray(); EIdData eIdData = new EIdData(); eIdData.identity = identity; eIdData.address = address; eIdData.photo = photo; // operate byte[] document = this.testedInstance.generateVcard(eIdData); // verify assertNotNull(document); assertTrue(document.length > 0); toTmpFile(document); }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doProgressiveBicubic(PlanarImage op) throws Exception { int dstWidth = 220; int w = op.getWidth(); while (w > dstWidth) { scale = 0.6f;// w w w . ja v a 2 s .c o m ParameterBlock pb = new ParameterBlock(); pb.addSource(op); pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BICUBIC)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); w = (int) (scale * w); } return op; }
From source file:omr.jai.RGBToBilevel.java
RGBToBilevel(final String fileName, boolean isErrorDiffusion) { // Load the file. PlanarImage src = JAI.create("fileload", fileName); // Load the ParameterBlock for the dithering operation // and set the operation name. ParameterBlock pb = new ParameterBlock(); pb.addSource(src);/*from ww w. j a v a 2 s .c om*/ String opName = null; if (isErrorDiffusion) { opName = "errordiffusion"; LookupTableJAI lut = new LookupTableJAI(new byte[][] { { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff }, { (byte) 0x00, (byte) 0xff } }); pb.add(lut); pb.add(KernelJAI.ERROR_FILTER_FLOYD_STEINBERG); } else { opName = "ordereddither"; ColorCube cube = ColorCube.createColorCube(DataBuffer.TYPE_BYTE, 0, new int[] { 2, 2, 2 }); pb.add(cube); pb.add(KernelJAI.DITHER_MASK_443); } // Create a layout containing an IndexColorModel which maps // zero to zero and unity to 255; force SampleModel to be bilevel. ImageLayout layout = new ImageLayout(); byte[] map = new byte[] { (byte) 0x00, (byte) 0xff }; ColorModel cm = new IndexColorModel(1, 2, map, map, map); layout.setColorModel(cm); SampleModel sm = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, src.getWidth(), src.getHeight(), 1); layout.setSampleModel(sm); // Create a hint containing the layout. RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); // Dither the image. final PlanarImage dst = JAI.create(opName, pb, hints); // Exit on window closing. addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { JAI.create("filestore", dst, fileName + ".out", "PNG", null); System.exit(0); } }); // Display the result. //// ATTENTION A REMPLACER : add(new ScrollingImagePanel(dst, dst.getWidth(), dst.getHeight())); pack(); setVisible(true); }
From source file:business.model.CaptchaModel.java
/** * * @param CaptchaText/*from w ww. jav a2 s.c om*/ * @return */ public static BufferedImage CreateCaptchaImageOld(String CaptchaText) { BufferedImage localBufferedImage = new BufferedImage(width, height, 1); try { Graphics2D localGraphics2D = localBufferedImage.createGraphics(); // List<Font> fonts = FontFactory.getListFont(); List<Font> fonts = new ArrayList<Font>(); if (fonts.isEmpty()) { fonts.add(new Font("Nimbus Roman No9 L", 1, 30)); fonts.add(new Font("VN-NTime", 1, 30)); fonts.add(new Font("DT-Times", 1, 30)); fonts.add(new Font("Times New Roman", 1, 30)); fonts.add(new Font("Vni-Book123", 1, 30)); fonts.add(new Font("VNI-Centur", 1, 30)); fonts.add(new Font("DT-Brookly", 1, 30)); } // fonts.add(loadFont("BINHLBI.TTF")); RenderingHints localRenderingHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); localRenderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); localGraphics2D.setRenderingHints(localRenderingHints); localGraphics2D.fillRect(0, 0, width, height); localGraphics2D.setColor(new Color(50, 50, 50)); Random localRandom = new Random(); int i = 0; int j = 0; for (int k = 0; k < CaptchaText.length(); k++) { i += 25 + Math.abs(localRandom.nextInt()) % 5; j = 25 + Math.abs(localRandom.nextInt()) % 20; int tmp = localRandom.nextInt(fonts.size() - 1); localGraphics2D.setFont(fonts.get(tmp)); localGraphics2D.drawChars(CaptchaText.toCharArray(), k, 1, i, j); } localBufferedImage = getDistortedImage(localBufferedImage); Graphics2D localGraphics2D2 = localBufferedImage.createGraphics(); localGraphics2D2.setRenderingHints(localRenderingHints); // localGraphics2D2.fillRect(0, 0, width, height); localGraphics2D2.setColor(new Color(50, 50, 50)); CubicCurve2D c = new CubicCurve2D.Double();// draw QuadCurve2D.Float with set coordinates for (int l = 0; l < 7; l++) { int x1 = Util.rand(0, width / 2); ; int x2 = Util.rand(width / 2, width); int y1 = Util.rand(0, height); int y2 = Util.rand(0, height); int ctrlx1 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly1 = y1; int ctrlx2 = (x1 + x2) / 4 * Util.rand(1, 3); int ctrly2 = y2; c.setCurve(x1, y1, ctrlx2, ctrly2, ctrlx1, ctrly1, x2, y2); localGraphics2D2.draw(c); // localGraphics2D2.drawLine(randomX1(), randomY1(), randomX2(), randomY2()); } localGraphics2D.dispose(); } catch (Exception e) { log.error(e.getMessage(), e); return null; } return localBufferedImage; }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleNearest(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);/*ww w . j a va2 s. c o m*/ pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }
From source file:org.esa.s2tbx.dataio.jp2.internal.JP2TileOpImage.java
/** * Factory method for creating a TileOpImage instance. * * @param imageFile The JP2 file//from w ww. ja v a 2s . co m * @param cacheDir The directory where decompressed tiles will be extracted * @param bandIdx The index of the band for which the operator is created * @param row The row of the tile in the scene layout * @param col The column of the tile in the scene layout * @param tileLayout The scene layout * @param imageModel The multi-level image model * @param dataType The data type of the tile raster * @param level The resolution at which the tile is created */ public static PlanarImage create(Path imageFile, Path cacheDir, int bandIdx, int row, int col, TileLayout tileLayout, MultiLevelModel imageModel, int dataType, int level) throws IOException { Assert.notNull(cacheDir, "cacheDir"); Assert.notNull(tileLayout, "imageLayout"); Assert.notNull(imageModel, "imageModel"); if (imageFile != null) { //jp2TileOpImage.setTileCache(null); // the MosaicOpImage will be in the cache return new JP2TileOpImage(imageFile, bandIdx, cacheDir, row, col, tileLayout, imageModel, dataType, level); } else { int targetWidth = tileLayout.tileWidth; int targetHeight = tileLayout.tileHeight; Dimension targetTileDim = getTileDimAtResolutionLevel(tileLayout.tileWidth, tileLayout.tileHeight, level); SampleModel sampleModel = ImageUtils.createSingleBandedSampleModel(dataType, targetWidth, targetHeight); ImageLayout imageLayout = new ImageLayout(0, 0, targetWidth, targetHeight, 0, 0, targetTileDim.width, targetTileDim.height, sampleModel, null); return ConstantDescriptor.create((float) imageLayout.getWidth(null), (float) imageLayout.getHeight(null), new Short[] { 0 }, new RenderingHints(JAI.KEY_IMAGE_LAYOUT, imageLayout)); } }
From source file:com.hmsinc.epicenter.spatial.render.SpatialScanRenderer.java
/** * @param context/*from w ww. java 2s . c o m*/ * @return */ private BufferedImage renderImage(final MapContext context, int width, int height) { logger.trace("Image width: {} height: {}", width, height); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics2D = (Graphics2D) image.getGraphics(); final GTRenderer renderer = new StreamingRenderer(); final RenderingHints h = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); h.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); h.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); h.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); h.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); renderer.setJava2DHints(h); renderer.setContext(context); renderer.paint(graphics2D, new Rectangle(width, height), context.getAreaOfInterest()); return image; }
From source file:com.alibaba.simpleimage.ScaleTest.java
public PlanarImage doScaleBilinear(PlanarImage op) throws Exception { ParameterBlock pb = new ParameterBlock(); pb.addSource(op);//from w ww .j ava2 s . co m pb.add(scale); pb.add(scale); pb.add(0.0F); pb.add(0.0F); pb.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR)); RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); op = JAI.create("scale", pb, qualityHints); return op; }