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:com.fusesource.forge.jmstest.persistence.rrd.RrdGraphPostProcessor.java
private void createThumbnail(BufferedImage image, String name, int thumbWidth, int thumbHeight) { double thumbRatio = (double) thumbWidth / (double) thumbHeight; int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double imageRatio = (double) imageWidth / (double) imageHeight; if (thumbRatio < imageRatio) { thumbHeight = (int) (thumbWidth / imageRatio); } else {/* w ww. jav a2 s .c o m*/ thumbWidth = (int) (thumbHeight * imageRatio); } BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); File thumbFile = new File(getWorkDir().getAbsolutePath() + "/" + name + "-thumb.png"); try { ImageIO.write(thumbImage, "PNG", thumbFile); } catch (IOException ioe) { log().error("Error creating thumbnail for: " + name); } }
From source file:costumetrade.common.verify.ImageVerification.java
public Pair<String, BufferedImage> create() { int x = 0, fontHeight = 0, codeY = 0; int red = 0, green = 0, blue = 0; x = width / (codeCount + 2);//? fontHeight = height - 2;// codeY = height - 4;/* w w w . j a v a 2 s . com*/ // ?buffer BufferedImage buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = buffImg.createGraphics(); // ? g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); // g.setFont(new Font("Arial", Font.PLAIN, fontHeight)); for (int i = 0; i < lineCount; i++) { int xs = RandomUtils.nextInt(0, width); int ys = RandomUtils.nextInt(0, height); int xe = xs + RandomUtils.nextInt(0, width / 8); int ye = ys + RandomUtils.nextInt(0, height / 8); red = RandomUtils.nextInt(0, 255); green = RandomUtils.nextInt(0, 255); blue = RandomUtils.nextInt(0, 255); g.setColor(new Color(red, green, blue)); g.drawLine(xs, ys, xe, ye); } // randomCode??? StringBuilder randomCode = new StringBuilder(); // ?codeCount?? for (int i = 0; i < codeCount; i++) { String strRand = String.valueOf(codeSequence[RandomUtils.nextInt(0, codeSequence.length)]); // ???? red = RandomUtils.nextInt(0, 255); green = RandomUtils.nextInt(0, 255); blue = RandomUtils.nextInt(0, 255); g.setColor(new Color(red, green, blue)); g.drawString(strRand, (i + 1) * x, codeY); // ?? randomCode.append(strRand); } // ????Session return new Pair<String, BufferedImage>(randomCode.toString(), buffImg); }
From source file:filters.collage.CropFilter.java
@Override protected void doFilter(BufferedImage image, OutputStream output, FilterOptions options, String format) throws IOException { com.jhlabs.image.CropFilter cropFilter = new com.jhlabs.image.CropFilter( options.get(FilterOption.X, Integer.class), options.get(FilterOption.Y, Integer.class), options.get(FilterOption.WIDTH, Integer.class), options.get(FilterOption.HEIGHT, Integer.class)); BufferedImage outputImage = new BufferedImage(options.get(FilterOption.WIDTH, Integer.class), options.get(FilterOption.HEIGHT, Integer.class), BufferedImage.TYPE_INT_RGB); cropFilter.filter(image, outputImage); ImageIO.write(outputImage, format, output); }
From source file:cpcc.ros.sim.osm.Camera.java
/** * Initialize the tile map./* w ww .j a v a 2 s . co m*/ */ private void initMap() { map = new BufferedImage(mapWidth * cfg.getTileWidth(), mapHeight * cfg.getTileHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = map.createGraphics(); tiles = new Graphics[mapWidth][mapHeight]; for (int w = 0; w < mapWidth; ++w) { for (int h = 0; h < mapHeight; ++h) { tiles[w][h] = g2d.create(w * cfg.getTileWidth(), h * cfg.getTileHeight(), cfg.getTileWidth(), cfg.getTileHeight()); } } }
From source file:com.lixiaocong.service.ImageCodeService.java
public BufferedImage getImage(HttpSession session) { //background/*from w w w. ja v a 2 s . co m*/ BufferedImage bi = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics graphics = bi.getGraphics(); graphics.setColor(randomColor()); graphics.fillRect(0, 0, WIDTH, HEIGHT); //content StringBuilder sb = new StringBuilder(); int len = ch.length; Random random = new Random(); for (int i = 0; i < 4; i++) { int index = random.nextInt(len); graphics.setColor(randomColor()); graphics.setFont(new Font(null, Font.BOLD + Font.ITALIC, 30)); graphics.drawString(ch[index] + "", i * 15 + 5, 25); sb.append(ch[index]); } session.setAttribute("imagecode", sb.toString()); //lines for (int i = 0; i < 4; i++) { graphics.setColor(randomColor()); graphics.drawLine(random.nextInt(WIDTH), random.nextInt(HEIGHT), random.nextInt(WIDTH), random.nextInt(HEIGHT)); } return bi; }
From source file:$.SayHiImage.java
private void writeImage(OutputStream out) throws IOException { BufferedImage img = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setPaint(Color.red);//w w w.jav a 2 s . c om g2d.setFont(new Font("Serif", Font.BOLD, 36)); g2d.drawString("Hi there, how are you doing today?", 5, g2d.getFontMetrics().getHeight()); g2d.dispose(); ImageIO.write(img, "jpg", out); }
From source file:ThumbnailTools.java
/** * Save the thumbnail to the specified file, with the specified type * @param file the file/*from w ww. j av a 2s . c om*/ * @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:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java
public java.awt.Paint getSeriesPaint(int row) { BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bufferedImage.createGraphics(); TexturePaint texture = null;// w w w. j a va 2s. com int rowNum = row + 1; int patNum = 13; int formula = rowNum - ((rowNum / patNum) * patNum); if (formula == 0) { big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 1) { big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 2) { Color color = Color.blue; big.setColor(Color.white); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(0, 1, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 3) { Color color = Color.yellow; big.setColor(Color.orange); big.fillRect(0, 0, 5, 5); big.setColor(color); big.fillRect(1, 1, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 4) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 5) { big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.pink); big.fillRect(0, 0, 4, 4); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 6) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(new Color(226, 199, 252)); big.fillRect(0, 0, 5, 5); big.setColor(Color.blue); big.setStroke(new BasicStroke(1.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 7) { big.setColor(Color.lightGray); big.fillRect(0, 0, 5, 5); big.setColor(Color.red); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 8) { float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[0]); for (int j = 1; j < x.length; j++) { path.lineTo(x[j], y[j]); } big.setColor(Color.blue); big.fillRect(0, 0, 5, 5); big.setColor(Color.cyan); big.setStroke(new BasicStroke(2.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 9) { Color color = new Color(0xBBBBDD); big.setColor(color); big.fillRect(0, 0, 5, 5); big.setColor(new Color(199, 201, 230)); big.fillRect(1, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 10) { float[] x = { 1, 2, 3, 4, 5 }; float[] y = { 1, 2, 3, 4, 5 }; GeneralPath path = new GeneralPath(); path.moveTo(x[0], y[1]); path.lineTo(x[1], y[0]); path.moveTo(x[0], y[2]); path.lineTo(x[2], y[0]); path.moveTo(x[0], y[3]); path.lineTo(x[3], y[0]); path.moveTo(x[0], y[4]); path.lineTo(x[4], y[0]); big.setColor(Color.red); big.fillRect(0, 0, 5, 5); big.setColor(new Color(242, 242, 193)); big.setStroke(new BasicStroke(3.0f)); big.draw(path); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 11) { big.setColor(new Color(252, 169, 171)); big.fillOval(0, 0, 5, 6); big.setColor(new Color(252, 230, 230)); big.fillOval(0, 0, 3, 3); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } else if (formula == 12) { big.setColor(Color.green); big.fillRect(0, 0, 5, 5); big.setColor(new Color(20, 178, 38)); big.fillRect(2, 2, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); texture = new TexturePaint(bufferedImage, r); } return texture; }
From source file:com.liusoft.dlog4j.util.ImageUtils.java
/** * ?/*from www . j a v a2 s .co m*/ * @param orig_img * @param obj_filename * @param p_width * @param p_height * @throws IOException */ public static String createPreviewImage(InputStream orig_img, String obj_filename, int p_width, int p_height) throws IOException { String extendName = StringUtils.getFileExtend(obj_filename).toLowerCase(); FileOutputStream newimage = null; InputStream fis = orig_img; try { if ("gif".equalsIgnoreCase(extendName)) { GifImage gifImage = GifDecoder.decode(fis); fis.close(); fis = null; GifImage newGif = GifTransformer.resize(gifImage, p_width, p_height, false); newimage = new FileOutputStream(obj_filename); GifEncoder.encode(newGif, newimage); } else { BufferedImage orig_portrait = (BufferedImage) ImageIO.read(fis); fis.close(); fis = null; // ?JPG? BufferedImage bi = new BufferedImage(p_width, p_height, BufferedImage.TYPE_INT_RGB); bi.getGraphics().drawImage(orig_portrait, 0, 0, p_width, p_height, null); if (!obj_filename.endsWith(".jpg")) obj_filename += ".jpg"; newimage = new FileOutputStream(obj_filename); ImageIO.write(bi, "jpg", newimage); } } finally { if (newimage != null) newimage.close(); if (fis != null) fis.close(); } return obj_filename; }
From source file:com.synnex.saas.platform.core.servlet.CaptchaServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* ww w.ja v a2 s . c om*/ 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); } }