List of usage examples for java.awt.image BufferedImage TYPE_INT_RGB
int TYPE_INT_RGB
To view the source code for java.awt.image BufferedImage TYPE_INT_RGB.
Click Source Link
From source file:be.fedict.eid.applet.service.PhotoServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doGet"); response.setContentType("image/jpg"); response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate, max-age=-1"); // http 1.1 response.setHeader("Pragma", "no-cache, no-store"); // http 1.0 response.setDateHeader("Expires", -1); ServletOutputStream out = response.getOutputStream(); HttpSession session = request.getSession(); byte[] photoData = (byte[]) session.getAttribute(IdentityDataMessageHandler.PHOTO_SESSION_ATTRIBUTE); if (null != photoData) { BufferedImage photo = ImageIO.read(new ByteArrayInputStream(photoData)); if (null == photo) { /*/*w w w. jav a 2s . com*/ * In this case we render a photo containing some error message. */ photo = new BufferedImage(140, 200, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = (Graphics2D) photo.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.setColor(Color.RED); graphics.setFont(new Font("Dialog", Font.BOLD, 20)); graphics.drawString("Photo Error", 0, 200 / 2); graphics.dispose(); ImageIO.write(photo, "jpg", out); } else { out.write(photoData); } } out.close(); }
From source file:com.aistor.common.servlet.ValidateCodeServlet.java
private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); /*//from www . j a v a 2s.c o m * ?? */ String width = request.getParameter("width"); String height = request.getParameter("height"); if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) { w = NumberUtils.toInt(width); h = NumberUtils.toInt(height); } BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); /* * ? */ createBackground(g); /* * ? */ String s = createCharacter(g); request.getSession().setAttribute("validateCode", s); g.dispose(); OutputStream out = response.getOutputStream(); ImageIO.write(image, "JPEG", out); out.close(); }
From source file:apm.common.servlet.ValidateCodeServlet.java
private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); /*//from w w w . ja v a 2s. c o m * ?? */ String width = request.getParameter("width"); String height = request.getParameter("height"); if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) { w = NumberUtils.toInt(width); h = NumberUtils.toInt(height); } BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); /* * ? */ createBackground(g); /* * ? */ String s = createCharacter(g); request.getSession().setAttribute(VALIDATE_CODE, s); g.dispose(); OutputStream out = response.getOutputStream(); ImageIO.write(image, "JPEG", out); out.close(); }
From source file:examples.utils.CifarReader.java
public static BufferedImage getImageFromArray(double[] pixels, int width, int height) { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int i = 0; i < pixels.length / IMAGE_DEPTH; ++i) { int rgb = new Color(Double.valueOf(pixels[i]).intValue(), Double.valueOf(pixels[i + 1024]).intValue(), Double.valueOf(pixels[i + 2048]).intValue()).getRGB(); image.setRGB(i % IMAGE_WIDTH, i / IMAGE_HIGHT, rgb); }//from w w w. j a va 2 s.c o m return image; }
From source file:com.eryansky.common.web.servlet.ValidateCodeServlet.java
private void createImage(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader("Pragma", "no-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setContentType("image/jpeg"); /*//www . ja va 2 s.c om * ?? */ String width = request.getParameter("width"); String height = request.getParameter("height"); if (StringUtils.isNumeric(width) && StringUtils.isNumeric(height)) { w = NumberUtils.toInt(width); h = NumberUtils.toInt(height); } BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); /* * ? */ createBackground(g); /* * ? */ String s = createCharacter(g); request.getSession().setAttribute(SysConstants.SESSION_VALIDATE_CODE, s); g.dispose(); OutputStream out = response.getOutputStream(); ImageIO.write(image, "JPEG", out); out.close(); }
From source file:dk.netdesign.common.osgi.config.osgi.OCD.java
public BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); if (imgWidth * height < imgHeight * width) { width = imgWidth * height / imgHeight; } else {/* w ww. j a v a 2s . c o m*/ height = imgHeight * width / imgWidth; } BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); try { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setBackground(background); g.clearRect(0, 0, width, height); g.drawImage(img, 0, 0, width, height, null); } finally { g.dispose(); } return newImage; }
From source file:de.laures.cewolf.util.ImageHelper.java
public static BufferedImage createImage(int width, int height) { // return GRAPHICS_CONV.createCompatibleImage(width, height); return new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); }
From source file:jmbench.plots.UtilPlotPdf.java
protected static BufferedImage draw(JFreeChart chart, int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, width, height)); g2.dispose();/*from w ww . j av a 2s . c om*/ return img; }
From source file:org.jrecruiter.service.impl.DataServiceImpl.java
/** {@inheritDoc} */ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public Image getGoogleMapImage(final BigDecimal latitude, final BigDecimal longitude, final Integer zoomLevel) { if (longitude == null) { throw new IllegalArgumentException("Longitude cannot be null."); }/*from w ww. j a v a2 s. c om*/ if (latitude == null) { throw new IllegalArgumentException("Latitude cannot be null."); } if (zoomLevel == null) { throw new IllegalArgumentException("ZoomLevel cannot be null."); } final URI url = GoogleMapsUtils.buildGoogleMapsStaticUrl(latitude, longitude, zoomLevel); BufferedImage img; try { URLConnection conn = url.toURL().openConnection(); img = ImageIO.read(conn.getInputStream()); } catch (UnknownHostException e) { LOGGER.error("Google static MAPS web service is not reachable (UnknownHostException).", e); img = new BufferedImage(GoogleMapsUtils.defaultWidth, 100, BufferedImage.TYPE_INT_RGB); final Graphics2D graphics = img.createGraphics(); final Map<Object, Object> renderingHints = CollectionUtils.getHashMap(); renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.addRenderingHints(renderingHints); graphics.setBackground(Color.WHITE); graphics.setColor(Color.GRAY); graphics.clearRect(0, 0, GoogleMapsUtils.defaultWidth, 100); graphics.drawString("Not Available", 30, 30); } catch (IOException e) { throw new IllegalStateException(e); } return img; }
From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer.java
/** * The resulting IVisualization shows a chart which consists a TimeSeries for each FeatureOfInterest * contained in the observationCollection. *///from ww w . ja va 2 s . c o m public IVisualization renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int width, int height) { JFreeChart chart = renderChart(observationCollection, paramCon); Plot plot = chart.getPlot(); // draw plot into image: BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, width, height); plot.draw(g, new Rectangle2D.Float(0, 0, width, height), null, null, null); return new StaticVisualization(image); }