List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:Composite.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();//from w ww. j av a 2 s .c o m int w = d.width; int h = d.height; BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, d.width, d.height); int rectx = w / 4; int recty = h / 4; gbi.setColor(new Color(0.0f, 0.0f, 1.0f, 1.0f)); gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100)); gbi.setColor(new Color(1.0f, 0.0f, 0.0f, 1.0f)); gbi.setComposite(ac); gbi.fill(new Ellipse2D.Double(rectx + rectx / 2, recty + recty / 2, 150, 100)); g2.drawImage(buffImg, null, 0, 0); }
From source file:com.neophob.sematrix.generator.Textwriter.java
/** * create image.//from w ww .java 2 s. c o m * * @param text the text */ public void createTextImage(String text) { //only load if needed if (StringUtils.equals(text, this.text)) { return; } this.text = text; BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D rect = layout.getBounds(); int h = (int) (0.5f + rect.getHeight()); maxXPos = (int) (0.5f + rect.getWidth()) + 5; ypos = internalBufferYSize - (internalBufferYSize - h) / 2; img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB); g2 = img.createGraphics(); g2.setColor(color); g2.setFont(font); g2.setClip(0, 0, maxXPos, internalBufferYSize); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawString(text, xpos, ypos); DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer(); textBuffer = dbi.getData(); g2.dispose(); wait = 0; xofs = 0; scrollRight = false; }
From source file:com.lcdfx.pipoint.PiPoint.java
public PiPoint(String[] args) { this.addWindowListener(new WindowAdapter() { @Override//from ww w .ja va 2 s. c o m public void windowClosing(WindowEvent ev) { shutDown(); } }); // add logging logger = Logger.getLogger(this.getClass().getName()); logger.log(Level.INFO, "PiPoint version " + PiPoint.class.getPackage().getImplementationVersion() + " running under " + System.getProperty("java.vm.name") + " v" + System.getProperty("java.vm.version")); // get command line options CommandLineParser parser = new BasicParser(); Map<String, String> cmdOptions = new HashMap<String, String>(); Options options = new Options(); options.addOption(new Option("f", "fullscreen", false, "fullscreen mode (no cursor)")); CommandLine cmd = null; try { cmd = parser.parse(options, args); for (Option option : cmd.getOptions()) { cmdOptions.put(option.getOpt(), option.getValue()); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar pipoint.jar", options); System.exit(0); } if (cmd.hasOption("f")) { setUndecorated(true); BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); getContentPane().setCursor(blankCursor); } // instantiate the RendererManager mgr = new DlnaRendererManager(this); mgr.refreshDevices(); nowPlayingPanel = new NowPlayingPanel(this); mgr.getRenderer().addListener(nowPlayingPanel); devicePanel = new DevicePanel(this); this.getContentPane().setPreferredSize(new Dimension(DISPLAY_WIDTH, DISPLAY_HEIGHT)); this.getContentPane().add(devicePanel); }
From source file:de.darkblue.bongloader2.utils.ToolBox.java
public static BufferedImage grayScale(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = newImage.getGraphics(); g.drawImage(image, 0, 0, null);/*ww w . ja va 2 s . co m*/ g.dispose(); return newImage; }
From source file:SWTUtils.java
/** * Converts an AWT image to SWT./* w w w. ja v a2s . co m*/ * * @param image the image (<code>null</code> not permitted). * * @return Image data. */ public static ImageData convertAWTImageToSWT(Image image) { if (image == null) { throw new IllegalArgumentException("Null 'image' argument."); } int w = image.getWidth(null); int h = image.getHeight(null); if (w == -1 || h == -1) { return null; } BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return convertToSWT(bi); }
From source file:TRescaleOp.java
public void createBufferedImages() { biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB); big = biSrc.createGraphics();//from w w w. j av a 2s. c o m big.drawImage(displayImage, 0, 0, this); biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB); bi = biSrc; }
From source file:com.l1j5.web.common.utils.ImageUtils.java
public static void getImageThumbnail(BufferedInputStream stream_file, String save, String type, int w) { try {//from w ww .java 2s . co m File file = new File(save); BufferedImage bi = ImageIO.read(stream_file); int width = bi.getWidth(); int height = bi.getHeight(); double ratio = (double) height / width; height = (int) (w * ratio); if (w < width) { width = w; } BufferedImage bufferIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Image atemp = bi.getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING); Graphics2D g2 = bufferIm.createGraphics(); g2.drawImage(atemp, 0, 0, width, height, null); ImageIO.write(bufferIm, type, file); } catch (Exception e) { log.error(e); } }
From source file:OffScreenTest.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer, null);//from ww w . j av a 2s . c o m drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); // create the main scene graph BranchGroup scene = createSceneGraph(drawRaster); // create the on-screen canvas OnScreenCanvas3D d = new OnScreenCanvas3D(config, false); add("Center", d); // create a simple universe u = new SimpleUniverse(d); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); // create an off Screen Canvas OffScreenCanvas3D c = new OffScreenCanvas3D(config, true, drawRaster); // set the offscreen to match the onscreen Screen3D sOn = d.getScreen3D(); Screen3D sOff = c.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); // attach the same view to the offscreen canvas View v = u.getViewer().getView(); v.addCanvas3D(c); // tell onscreen about the offscreen so it knows to // render to the offscreen at postswap d.setOffScreenCanvas(c); u.addBranchGraph(scene); v.stopView(); // Make sure that image are render completely // before grab it in postSwap(). d.setImageReady(); v.startView(); }
From source file:com.igormaznitsa.jhexed.values.HexSVGImageValue.java
@Override public void prerasterizeIcon(final Shape shape) { try {/*from ww w . ja va2s. c o m*/ final Rectangle r = shape.getBounds(); final BufferedImage img = this.image.rasterize(r.width, r.height, BufferedImage.TYPE_INT_ARGB); final BufferedImage result = new BufferedImage(r.width, r.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setClip(shape); g.drawImage(img, 0, 0, null); g.dispose(); this.prerasterized = result; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:ConvertUtil.java
/** * Converts the source image to 32-bit colour with transparency (ARGB). * /* w ww . j a v a 2 s .c o m*/ * @param src * the source image to convert * @return a copy of the source image with a 32-bit colour depth. */ public static BufferedImage convert32(BufferedImage src) { BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB); ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(), dest.getColorModel().getColorSpace(), null); cco.filter(src, dest); return dest; }