List of usage examples for java.awt.image BufferedImage getGraphics
public java.awt.Graphics getGraphics()
From source file:net.sqs2.omr.session.logic.PageImageRenderer.java
public static BufferedImage createImage(long sessionID, SessionSource sessionSource, FormMaster master, SourceDirectory rowGroupSourceDirectory, int rowIndex, int focusedColumnIndex, int pageIndex, Rectangle scope) throws IOException, ConfigSchemeException { float densityThreshold = ((SourceConfig) rowGroupSourceDirectory.getConfiguration().getConfig() .getPrimarySourceConfig()).getMarkRecognitionConfig().getMarkRecognitionDensityThreshold(); PageID pageID = rowGroupSourceDirectory.getPageIDList().get(rowIndex * master.getNumPages() + pageIndex); File file = new File(rowGroupSourceDirectory.getRoot(), pageID.getFileResourceID().getRelativePath()); BufferedImage src = ImageFactory.createImage(FilenameUtils.getExtension(file.getName()), file, pageID.getIndexInFile());/*from w w w . j a va 2 s.com*/ Logger.getLogger("PageImageRenderer").info("create image : " + file); BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB); copyImage(src, image); if (scope != null) { //PageTaskAccessor pageTaskAccessor = new PageTaskAccessor(sessionSource.getRootDirectory()); PageTaskAccessor pageTaskAccessor = sessionSource.getContentAccessor().getPageTaskAccessor(); OMRPageTask pageTask = pageTaskAccessor.get(pageIndex + 1, pageID); SourceDirectoryConfiguration configHandler = getSourceDirectoryConfiguration(sessionSource, pageTask); SourceConfig sourceConfig = (SourceConfig) configHandler.getConfig().getSourceConfig( pageTask.getPageID().getFileResourceID().getRelativePath(), pageTask.getProcessingPageNumber()); drawPageState(pageTask, sourceConfig, pageIndex, densityThreshold, master, image, focusedColumnIndex, scope); // TODO: draw double-mark ignorance and no-mark recovery pageTaskAccessor.flush(); } image.getGraphics().finalize(); return image; }
From source file:org.polymap.core.data.image.ImageGrayscaleProcessor.java
protected Image grayscale(Image image) { long start = System.currentTimeMillis(); // load image data new javax.swing.ImageIcon(image).getImage(); if (!(image instanceof BufferedImage)) { BufferedImage bimage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = bimage.getGraphics(); g.drawImage(image, 0, 0, null);//from w ww . j ava 2s. c o m g.dispose(); image = bimage; } // grayscale ColorConvertOp filter = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); BufferedImage grayImage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = grayImage.getGraphics(); filter.filter((BufferedImage) image, grayImage); g.dispose(); log.info("Gray scaling took: " + (System.currentTimeMillis() - start) + "ms"); return grayImage; }
From source file:org.pentaho.reporting.libraries.base.util.WaitingImageObserver.java
/** * The workerthread. Simply draws the image to a BufferedImage's Graphics-Object and waits for the AWT to load the * image./*from w w w . j a va 2s . c om*/ */ public synchronized void waitImageLoaded() { if (this.lock == false) { return; } final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); final Graphics g = img.getGraphics(); try { while (this.lock && error == false) { lastUpdate = System.currentTimeMillis(); if (g.drawImage(this.image, 0, 0, img.getWidth(this), img.getHeight(this), this)) { return; } try { wait(500); } catch (InterruptedException e) { LOGGER.info("WaitingImageObserver.waitImageLoaded(): InterruptedException thrown", e); } if (lock == false) { return; } if (maxLoadTime > 0 && lastUpdate < (System.currentTimeMillis() - maxLoadTime)) { error = true; lock = false; LOGGER.info("WaitingImageObserver.waitImageLoaded(): Image loading reached timeout."); return; } } } finally { g.dispose(); } }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImageINT_ARGB() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;/*from ww w . ja va 2 s. c om*/ } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-intargb.pdf"); }
From source file:org.sejda.sambox.pdmodel.graphics.image.JPEGFactoryTest.java
@Test public void testCreateFromImage4BYTE_ABGR() throws IOException { // workaround Open JDK bug // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044758 if (System.getProperty("java.runtime.name").equals("OpenJDK Runtime Environment") && (System.getProperty("java.specification.version").equals("1.6") || System.getProperty("java.specification.version").equals("1.7") || System.getProperty("java.specification.version").equals("1.8"))) { return;/* w w w .ja va 2 s . c o m*/ } PDDocument document = new PDDocument(); BufferedImage image = ImageIO.read(JPEGFactoryTest.class.getResourceAsStream("jpeg.jpg")); // create an ARGB image int width = image.getWidth(); int height = image.getHeight(); BufferedImage argbImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics ag = argbImage.getGraphics(); ag.drawImage(image, 0, 0, null); ag.dispose(); for (int x = 0; x < argbImage.getWidth(); ++x) { for (int y = 0; y < argbImage.getHeight(); ++y) { argbImage.setRGB(x, y, (argbImage.getRGB(x, y) & 0xFFFFFF) | ((y / 10 * 10) << 24)); } } PDImageXObject ximage = JPEGFactory.createFromImage(argbImage); validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName()); assertNotNull(ximage.getSoftMask()); validate(ximage.getSoftMask(), 8, width, height, "jpg", PDDeviceGray.INSTANCE.getName()); assertTrue(colorCount(ximage.getSoftMask().getImage()) > image.getHeight() / 10); doWritePDF(document, ximage, testResultsDir, "jpeg-4bargb.pdf"); }
From source file:de.romankreisel.faktotum.beans.BundesbruderBean.java
private Byte[] storeImageToByteArray(Image image) throws IOException { if (!(image instanceof RenderedImage)) { BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); newImage.getGraphics().drawImage(image, 0, 0, null); image = newImage;/* www .ja v a 2 s . c om*/ } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write((RenderedImage) image, "jpg", byteArrayOutputStream); byteArrayOutputStream.flush(); byte[] imageInByte = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.close(); return ArrayUtils.toObject(imageInByte); }
From source file:org.springframework.boot.ImageBanner.java
private BufferedImage resizeImage(BufferedImage image, int width, int height) { if (width < 1) { width = 1;/*from w w w. j ava2 s . co m*/ } if (height <= 0) { double aspectRatio = (double) width / image.getWidth() * 0.5; height = (int) Math.ceil(image.getHeight() * aspectRatio); } BufferedImage resized = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Image scaled = image.getScaledInstance(width, height, Image.SCALE_DEFAULT); resized.getGraphics().drawImage(scaled, 0, 0, null); return resized; }
From source file:org.deegree.securityproxy.wms.responsefilter.clipping.SimpleRasterClipper.java
private void executeClipping(Geometry visibleArea, Geometry imgBboxInVisibleAreaCrs, BufferedImage inputImage, BufferedImage outputImage) throws FactoryException, TransformException { Graphics2D graphics = (Graphics2D) outputImage.getGraphics(); LiteShape clippingArea = retrieveWorldToScreenClippingArea(visibleArea, imgBboxInVisibleAreaCrs, inputImage);//from w w w.ja va 2 s. co m graphics.clip(clippingArea); graphics.drawImage(inputImage, null, 0, 0); }
From source file:test.unit.be.fedict.eid.applet.service.KmlGeneratorTest.java
@Test public void identityWithAddressAndPhotoKml() throws Exception { // setup//from www . j a v a2 s.c om 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/*from w w w . j ava 2 s . c om*/ 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); }