Package java.awt.image

Examples of java.awt.image.BufferedImage


public class LineButton extends JButton {

  public LineButton() {
    super();
   
    BufferedImage image = new BufferedImage(22, 22, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = image.createGraphics();
    g2.setColor(new Color(255,0,0,0));
    g2.fillRect(0, 0, 22, 22);
   
    g2.setColor(getForeground());
    g2.drawLine(0, 11, 22, 11);
View Full Code Here


* A wrapper for an image that uses the ImageIO Framework.
*/
public class ImageIOGenerator extends ImageGenerator {

    protected void write(ImageWrapper wrapper, ImageWriter writer, float quality, boolean alpha) throws IOException {
        BufferedImage bi = wrapper.getBufferedImage();
        // Set some parameters
        ImageWriteParam param = writer.getDefaultWriteParam();
        if (param.canWriteCompressed() &&
            quality >= 0.0 && quality <= 1.0) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            String[] types = param.getCompressionTypes();
            // If compression types are defined, but none is set, set the first one,
            // since setCompressionQuality, which requires MODE_EXPLICIT to be set,
            // will complain otherwise.
            if (types != null && param.getCompressionType() == null) {
                param.setCompressionType(types[0]);
            }
            param.setCompressionQuality(quality);
        }
        if (param.canWriteProgressive())
            param.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
        // if bi has type ARGB and alpha is false, we have to tell the writer to not use the alpha channel:
        // this is especially needed for jpeg files where imageio seems to produce wrong jpeg files right now...
        if (bi.getType() == BufferedImage.TYPE_INT_ARGB
            && !alpha) {
            // create a new BufferedImage that uses a WritableRaster of bi, with all the bands except the alpha band:
            WritableRaster raster = bi.getRaster();
            WritableRaster newRaster = raster.createWritableChild(
                0, 0, raster.getWidth(), raster.getHeight(),
                0, 0, new int[] {0, 1, 2 }
            );
            // create a ColorModel that represents the one of the ARGB except the alpha channel:
            DirectColorModel cm = (DirectColorModel) bi.getColorModel();
            DirectColorModel newCM = new DirectColorModel(
                cm.getPixelSize(), cm.getRedMask(),
                cm.getGreenMask(), cm.getBlueMask());
            // now create the new buffer that is used ot write the image:
            BufferedImage rgbBuffer = new BufferedImage(newCM,
                newRaster, false, null);
            writer.write(null, new IIOImage(rgbBuffer, null,
                null), param);
        } else {
            writer.write(null, new IIOImage(bi, null, null),
View Full Code Here

   */
  protected static BufferedImage createImage(JComponent component, Rectangle region)
  throws IOException {
    boolean opaqueValue = component.isOpaque();
    component.setOpaque( true );
    BufferedImage image = new BufferedImage(region.width,
        region.height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.translate(-region.getX(), -region.getY());
    //g2d.setClip( region );
    component.paint( g2d );
    g2d.dispose();
    component.setOpaque( opaqueValue );
View Full Code Here

            try {
                tracker.waitForAll();
            } catch (InterruptedException e) {
                throw new IOException(e.getMessage());
            }
            BufferedImage bufImage = new BufferedImage(
                    image.getWidth(null),
                    image.getHeight(null),
                    BufferedImage.TYPE_INT_ARGB);

            Graphics g = bufImage.createGraphics();
            g.drawImage(image, 0, 0, null);
            return bufImage;
        }
    }
View Full Code Here

                  false,
                  tree.isExpanded(path),
                  tree.getModel() .isLeaf(path.getLastPathComponent()),
                  0, false);// returning the label
          lbl.setBounds(pathBounds);// setting bounds to lbl
          image = new BufferedImage(lbl.getWidth(), lbl.getHeight(),
              java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);// buffered
                                      // image
                                      // reference
                                      // passing
                                      // the
View Full Code Here

    private void export(Circuit circuit) {
      Bounds bds = circuit.getBounds(canvas.getGraphics())
        .expand(BORDER_SIZE);
      int width = (int) Math.round(bds.getWidth() * scale);
      int height = (int) Math.round(bds.getHeight() * scale);
      BufferedImage img = new BufferedImage(width, height,
          BufferedImage.TYPE_INT_RGB);
      Graphics base = img.getGraphics();
      Graphics g = base.create();
      g.setColor(Color.white);
      g.fillRect(0, 0, width, height);
      g.setColor(Color.black);
      if (g instanceof Graphics2D) {
View Full Code Here

  public RenderedImage renderImage(Image img) {
    int width = img.getWidth(null);
    int height = img.getHeight(null);

    // Create a buffered image in which to draw
    BufferedImage bufferedImage = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);

    // Create a graphics contents on the buffered image
    Graphics2D g2d = bufferedImage.createGraphics();

    g2d.drawImage(img, 0, 0, null);

    // Graphics context no longer needed so dispose it
    g2d.dispose();
View Full Code Here

    if ((currentWidth == width) && (currentHeight == height)) {
      return icon;
    }
    try {
      // Create Image with Icon
      BufferedImage iconImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),
          BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2 = iconImage.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
          RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      g2.setRenderingHint(RenderingHints.KEY_RENDERING,
          RenderingHints.VALUE_RENDER_QUALITY);
      AffineTransform z = g2.getTransform();
      g2.setTransform(z);
      icon.paintIcon(null, g2, 0, 0);
      g2.dispose();
      BufferedImage scaled = scaleDown(iconImage, width, height);
      // Return new Icon
      return new ImageIcon(scaled);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
View Full Code Here

  public static BufferedImage scaleIconToBufferedImage(BufferedImage img,
      int width, int height, int type, Color backgroundColor) {
    // Scale Image
    Image image = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);

    BufferedImage im = new BufferedImage(width, height, type);

    Graphics2D g2 = im.createGraphics();
    if (backgroundColor != null) {
      g2.setColor(backgroundColor);
      g2.fillRect(0, 0 , width, height);
    }

    g2.drawImage(image, null, null);
    g2.dispose();

    im.flush();
    return im;

  }
View Full Code Here

      return scaleIconToBufferedImage(img, targetWidth, targetHeight);
    }

    int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB
        : BufferedImage.TYPE_INT_ARGB;
    BufferedImage result = img;
    int w = img.getWidth();
    int h = img.getHeight();

    do {
      w /= 2;
      if (w < targetWidth) {
        w = targetWidth;
      }
      h /= 2;
      if (h < targetHeight) {
        h = targetHeight;
      }

      BufferedImage tmp = new BufferedImage(w, h, type);
      Graphics2D g2 = tmp.createGraphics();
      g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g2.drawImage(result, 0, 0, w, h, null);
      g2.dispose();

      result = tmp;
View Full Code Here

TOP

Related Classes of java.awt.image.BufferedImage

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.