List of usage examples for java.awt.image BufferedImage getGraphics
public java.awt.Graphics getGraphics()
From source file:org.mskcc.cbio.portal.util.MakeOncoPrint.java
private static FontMetrics getFontMetrics() { // this font/size corresponds to .oncoprint td specified in global_portal.css BufferedImage image = new BufferedImage(HEADER_CANVAS_WIDTH_PIXELS, HEADER_CANVAS_WIDTH_PIXELS, BufferedImage.TYPE_INT_RGB); Font portalFont = new Font("verdana", Font.PLAIN, 12); // outta here return image.getGraphics().getFontMetrics(portalFont); }
From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java
/** * Gets handle on the 2D graphics image object for the graph ready to * change (eg. add text to)./*from w w w . ja va 2 s . c o m*/ * * @param graphImage The current graph image * @return The 2D object handle */ private Graphics2D get2DGraphics(BufferedImage graphImage) { Graphics2D graphics2D = (Graphics2D) graphImage.getGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setColor(Color.BLACK); return graphics2D; }
From source file:net.sqs2.omr.session.logic.PageImageRenderer.java
private static void drawPageState(PageTask pageTask, SourceConfig sourceConfig, //SourceDirectoryConfiguration configHandler, int pageIndex, float densityThreshold, FormMaster master, BufferedImage image, int focusedColumnIndex, Rectangle scope) throws IOException { PageTaskResult pageTaskResult = pageTask.getPageTaskResult(); PageTaskException pageTaskException = pageTask.getPageTaskException(); FrameConfig frameConfig = sourceConfig.getFrameConfig(); DeskewGuideAreaConfig deskewGuideAreaConfig = frameConfig.getDeskewGuideAreaConfig(); MarkRecognitionConfig markRecognizationConfig = sourceConfig.getMarkRecognitionConfig(); float headerVerticalMargin = deskewGuideAreaConfig.getHeaderVerticalMargin(); float footerVerticalMargin = deskewGuideAreaConfig.getFooterVerticalMargin(); float deskewGuideAreaHeight = deskewGuideAreaConfig.getHeight(); float deskewGuideAreaHorizontalMargin = deskewGuideAreaConfig.getHeaderVerticalMargin(); int w = image.getWidth(); int h = image.getHeight(); Graphics2D g = (Graphics2D) image.getGraphics(); g.setColor(HEADER_FOOTER_COLOR);//from w ww . j a v a 2s .c om g.fillRect((int) (w * deskewGuideAreaHorizontalMargin), (int) (h * headerVerticalMargin), (int) (w - 2 * w * deskewGuideAreaHorizontalMargin), (int) (h * deskewGuideAreaHeight)); g.fillRect((int) (w * deskewGuideAreaHorizontalMargin), (int) (h - h * (footerVerticalMargin + deskewGuideAreaHeight) - 1), (int) (w - 2 * w * deskewGuideAreaHorizontalMargin), (int) (h * deskewGuideAreaHeight)); if (pageTaskResult != null) { Point2D[] corners = pageTaskResult.getDeskewGuideCenterPoints(); DeskewedImageSource pageSource = drawCorners(master, corners, image, g); drawFormAreas(pageIndex, densityThreshold, (FormMaster) master, pageTaskResult, g, markRecognizationConfig, pageSource, focusedColumnIndex, scope); } if (pageTaskException != null) { PageTaskExceptionModel model = pageTaskException.getExceptionModel(); if (model instanceof PageFrameExceptionModel) { PageFrameExceptionModel m = (PageFrameExceptionModel) model; drawCorners(master, m.getCorners(), image, g); } } }
From source file:ThumbnailTools.java
/** * Save the thumbnail to the specified file, with the specified type * @param file the file/*from w ww . ja v a2 s. c o m*/ * @param imageType the image type */ public void saveThumbnail(File file, String imageType) { if (thumb != null) { BufferedImage bi = new BufferedImage(thumb.getIconWidth(), thumb.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(thumb.getImage(), 0, 0, null); try { ImageIO.write(bi, imageType, file); } catch (IOException ioe) { throw new RuntimeException("Error occured saving thumbnail"); } } else { throw new RuntimeException("Thumbnail have to be created before."); } }
From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from ww w .jav a 2 s . com*/ int width = 50; int height = 18; String captchaCode = RandomStringUtils.random(4, true, true); HttpSession session = request.getSession(true); session.setAttribute("captchaCode", captchaCode); response.setContentType("images/jpeg"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); ServletOutputStream out = response.getOutputStream(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); Font mFont = new Font("Times New Roman", Font.BOLD, 18); g.setFont(mFont); g.setColor(getRandColor(160, 200)); Random random = new Random(); for (int i = 0; i < 155; i++) { int x2 = random.nextInt(width); int y2 = random.nextInt(height); int x3 = random.nextInt(12); int y3 = random.nextInt(12); g.drawLine(x2, y2, x2 + x3, y2 + y3); } g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); g.drawString(captchaCode, 2, 16); g.dispose(); ImageIO.write((BufferedImage) image, "JPEG", out); out.close(); } catch (Exception e) { logger.error("Generate captcha failed.", e); } }
From source file:com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon.java
public synchronized Image getImage(final double scale) { if (Double.compare(this.currentScaleFactor, scale) != 0) { this.scaledCachedImage = null; }//ww w . j av a 2s . c o m if (this.scaledCachedImage == null) { this.currentScaleFactor = scale; final int imgw = this.baseImage.getWidth(null); final int imgh = this.baseImage.getHeight(null); final int scaledW = (int) Math.round(imgw * this.baseScaleX * scale); final int scaledH = (int) Math.round(imgh * this.baseScaleY * scale); final BufferedImage img = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = (Graphics2D) img.getGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.drawImage(this.baseImage, 0, 0, scaledW, scaledH, null); g.dispose(); this.scaledCachedImage = img; } return this.scaledCachedImage; }
From source file:org.pmedv.core.app.PostApplicationStartupConfigurer.java
public PostApplicationStartupConfigurer(String fileLocation) { this.fileLocation = fileLocation; log.info(AppContext.getName() + " initialized."); BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); g.setColor(Color.BLACK);// ww w. j av a 2 s.c o m g.fillRect(0, 0, 16, 16); AppContext.getContext().getBean(ApplicationWindow.class).getStatusLabel().setIcon(new ImageIcon(image)); }
From source file:cpcc.core.utils.PngImageStreamResponseTest.java
@Test public void shouldConvertBufferedImage() throws IOException { BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB); Graphics gr = image.getGraphics(); gr.setColor(Color.GREEN);// w ww. ja v a2s . c o m gr.drawLine(0, 0, 1, 1); gr.setColor(Color.BLACK); gr.drawLine(1, 1, 0, 0); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "PNG", baos); byte[] expected = baos.toByteArray(); StreamResponse response = PngImageStreamResponse.convertImageToStreamResponse(image); assertThat(response.getStream()).isNotNull(); byte[] actual = IOUtils.toByteArray(response.getStream()); assertThat(actual).isEqualTo(expected); }
From source file:net.d53dev.dslfy.web.service.GifService.java
public BufferedImage convertRGBAToGIF(BufferedImage src, int transColor) { BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics g = dst.getGraphics(); g.setColor(new Color(transColor)); g.fillRect(0, 0, dst.getWidth(), dst.getHeight()); {//ww w . j av a2 s. co m IndexColorModel indexedModel = (IndexColorModel) dst.getColorModel(); WritableRaster raster = dst.getRaster(); int sample = raster.getSample(0, 0, 0); int size = indexedModel.getMapSize(); byte[] rr = new byte[size]; byte[] gg = new byte[size]; byte[] bb = new byte[size]; indexedModel.getReds(rr); indexedModel.getGreens(gg); indexedModel.getBlues(bb); IndexColorModel newModel = new IndexColorModel(8, size, rr, gg, bb, sample); dst = new BufferedImage(newModel, raster, dst.isAlphaPremultiplied(), null); } dst.createGraphics().drawImage(src, 0, 0, null); return dst; }
From source file:com.fusesource.forge.jmstest.persistence.rrd.RrdGraphPostProcessor.java
@Override public void processData() { super.processData(); RrdDb db = getDatabase().getDatabase(); for (int i = 0; i < db.getArcCount(); i++) { Archive arch = db.getArchive(i); try {// w ww.j av a2 s . com for (String dsName : db.getDsNames()) { String probeName = getDatabase().getDescriptorByPhysicalName(dsName).getName(); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss"); StringBuffer title = new StringBuffer(probeName); title.append(" "); title.append(sdf.format(new Date(arch.getStartTime() * 1000))); title.append("-"); title.append(sdf.format(new Date(arch.getEndTime() * 1000))); log().info("Creating Graph: " + title); RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setTitle(title.toString()); graphDef.setTimeSpan(arch.getStartTime(), arch.getEndTime()); graphDef.datasource(dsName, getDbFileName(), dsName, ConsolFun.AVERAGE); graphDef.setStep(arch.getArcStep()); graphDef.setWidth(800); graphDef.setHeight(600); graphDef.line(dsName, Color.BLUE, probeName, 2.0f); graphDef.setImageFormat("PNG"); graphDef.setFilename(getWorkDir().getAbsolutePath() + "/" + probeName + ".png"); RrdGraph graph = new RrdGraph(graphDef); BufferedImage bi = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); graph.render(bi.getGraphics()); createThumbnail(bi, probeName, 40, 30); } catch (Exception e) { log().error("Error generating graph for probe " + probeName, e); } } } catch (IOException ioe) { log().error("Error retrieving datasource names from RRD database ", ioe); } } }