List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:com.seleniumtests.util.imaging.ImageProcessor.java
/** * cut part of an image/*from w w w .j a va 2s .c o m*/ * @param img source image * @param cropX x coord of the top left point * @param cropY y coord of the top left point * @param width width of picture portion to keep * @param height height of picture portion to keep * @return cut image */ public static BufferedImage cropImage(BufferedImage img, Integer cropX, Integer cropY, Integer width, Integer height) { BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); newImg.createGraphics().drawImage(img, 0, 0, width, height, cropX, cropY, cropX + width, cropY + height, null); return newImg; }
From source file:Main.java
private Image createImage(Color color) { BufferedImage bImg = new BufferedImage(Width, Height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bImg.createGraphics(); g2.setBackground(color);//ww w . j a v a 2s .co m g2.clearRect(0, 0, Width, Height); g2.dispose(); return bImg; }
From source file:net.dv8tion.jda.utils.AvatarUtil.java
private static BufferedImage resize(BufferedImage originalImage) { BufferedImage resizedImage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_RGB); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(originalImage, 0, 0, SIZE, SIZE, Color.white, null); g.dispose();/* ww w . ja v a2s . c om*/ return resizedImage; }
From source file:com.spstudio.common.image.ImageUtils.java
public static BufferedImage zoom(BufferedImage sourceImage, int width, int height) { BufferedImage zoomImage = new BufferedImage(width, height, sourceImage.getType()); Image image = sourceImage.getScaledInstance(width, height, Image.SCALE_SMOOTH); Graphics gc = zoomImage.getGraphics(); gc.setColor(Color.WHITE);//w w w . j a va 2 s. c o m gc.drawImage(image, 0, 0, null); return zoomImage; }
From source file:DBMS.UpdateFileUpload.java
private static BufferedImage resizeImage(BufferedImage originalImage, int type) { BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); g.dispose();// w w w . j a va2s.co m return resizedImage; }
From source file:apiserver.services.images.services.jhlabs.MaskFilterService.java
public Object doFilter(Message<?> message) throws MessageConfigException { MaskJob props = (MaskJob) message.getPayload(); Object maskImage = props.getMask(); try {//from w w w . jav a2s. co m BufferedImage bufferedImage = props.getBufferedImage(); if (bufferedImage == null) { throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY); } BufferedImage destImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImage.getType()); //run filter ApplyMaskFilter filter = new ApplyMaskFilter(); filter.setDestination(destImage); filter.setMaskImage(bufferedImage); BufferedImage outFile = filter.filter(bufferedImage, null); props.setBufferedImage(outFile); return message; } catch (Throwable e) { //log.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:arlocros.Imshow.java
/** * @param opencvImage//from w w w.j av a 2 s . c o m */ public static void show(Mat opencvImage) { Dimension frameSize = new Dimension(opencvImage.rows(), opencvImage.cols()); if (frame == null) { frame = new Imshow("", frameSize.height, frameSize.width); frame.Window.setVisible(true); frame.Window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); if (frame.SizeCustom) { Imgproc.resize(opencvImage, opencvImage, new Size(frame.Height, frame.Width)); } } BufferedImage bufImage = null; try { int type = BufferedImage.TYPE_BYTE_GRAY; if (opencvImage.channels() > 1) { type = BufferedImage.TYPE_3BYTE_BGR; } int bufferSize = opencvImage.channels() * opencvImage.cols() * opencvImage.rows(); byte[] b = new byte[bufferSize]; opencvImage.get(0, 0, b); BufferedImage bufferedImage = new BufferedImage(opencvImage.cols(), opencvImage.rows(), type); final byte[] targetPixels = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData(); System.arraycopy(b, 0, targetPixels, 0, b.length); bufImage = bufferedImage; frame.image.setImage(bufImage); frame.Window.pack(); frame.label.updateUI(); //frame.Window.setVisible(true); } catch (RuntimeException e) { logger.info("Exception while visualizing.", e); } }
From source file:com.springsecurity.plugin.util.ImageResizer.java
public BufferedImage scale(File icon, int targetWidth, int targetHeight) { BufferedImage ret = null;/*w w w . ja v a2 s . c o m*/ if (icon.exists()) { try { BufferedImage img = ImageIO.read(icon); ret = img; int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage scratchImage = null; Graphics2D g2 = null; int w = img.getWidth(); int h = img.getHeight(); int prevW = w; int prevH = h; do { if (w > targetWidth) { w /= 2; w = (w < targetWidth) ? targetWidth : w; } if (h > targetHeight) { h /= 2; h = (h < targetHeight) ? targetHeight : h; } if (scratchImage == null) { scratchImage = new BufferedImage(w, h, type); g2 = scratchImage.createGraphics(); } g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(ret, 0, 0, w, h, 0, 0, prevW, prevH, null); prevW = w; prevH = h; ret = scratchImage; } while (w != targetWidth || h != targetHeight); if (g2 != null) { g2.dispose(); } if (targetWidth != ret.getWidth() || targetHeight != ret.getHeight()) { scratchImage = new BufferedImage(targetWidth, targetHeight, type); g2 = scratchImage.createGraphics(); g2.drawImage(ret, 0, 0, null); g2.dispose(); ret = scratchImage; } } catch (IOException e) { } } return ret; }
From source file:com.teasoft.teavote.controller.ElectionInfoController.java
private static BufferedImage resizeImage(BufferedImage originalImage, int type) { BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); g.dispose();//from w w w.j a va2s . co m return resizedImage; }
From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java
/** * Default constructor./*from w ww. j a va 2 s . co m*/ */ public TilingPatternExample() { //Created TexturePaint instance this.tile = new BufferedImage(40, 20, BufferedImage.TYPE_INT_RGB); Graphics2D tileg2d = tile.createGraphics(); tileg2d.setBackground(Color.WHITE); tileg2d.clearRect(0, 0, tile.getWidth(), tile.getHeight()); tileg2d.setColor(Color.BLUE); tileg2d.fillOval(2, 2, tile.getWidth() - 2, tile.getHeight() - 2); tileg2d.dispose(); Rectangle2D rect = new Rectangle2D.Double(2, 2, tile.getWidth() / 2.0, tile.getHeight() / 2.0); this.paint = new TexturePaint(tile, rect); }