Examples of BufferedImage


Examples of java.awt.image.BufferedImage

    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

Examples of java.awt.image.BufferedImage

  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

Examples of java.awt.image.BufferedImage

      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

Examples of java.awt.image.BufferedImage

   * @param ic
   * @return ImageIcon
   * @since 2.1
   */
  public static ImageIcon createChannelIcon(Icon ic) {
    BufferedImage img = new BufferedImage(getChannelIconWidth(), getChannelIconHeight(), BufferedImage.TYPE_INT_RGB);

    if (ic == null) {
      ic = new ImageIcon("./imgs/tvbrowser16.png");
    }

    int height = 20;
    int width = 40;

    if ((ic.getIconWidth() != 0) && (ic.getIconHeight() != 0)) {
      double iWidth = ic.getIconWidth();
      double iHeight = ic.getIconHeight();
      if (iWidth / iHeight < 2.0) {
        width = (int) (iWidth * (20.0 / iHeight));
      } else {
        height = (int) (iHeight * (40.0 / iWidth));
      }
    }
    ic = scaleIcon(ic, width, height);

    Graphics2D g = img.createGraphics();

    g.setColor(Color.WHITE);
    g.fillRect(1, 1, 40, 20);

    int x = 1 + 20 - ic.getIconWidth() / 2;
View Full Code Here

Examples of java.awt.image.BufferedImage

    /**
     * Create a small Icon with the current Color
     * @return Icon with Color
     */
    private Icon createIcon() {
        BufferedImage img = new BufferedImage(50, 10, BufferedImage.TYPE_INT_RGB);
       
        Graphics2D g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
       
        g.setColor(Color.WHITE);
        g.fillRect(0,0,50,10);
View Full Code Here

Examples of java.awt.image.BufferedImage

                outname = fileName + ".jpg";
            }
            RenderedOp img = JAI.create("fileload", fileName);
            ColorModel cm = img.getColorModel();
            WritableRaster imgRaster = img.copyData();
            BufferedImage bi = new BufferedImage(cm, imgRaster, false, new Hashtable());
            ImageIO.write((RenderedImage) bi, "jpg", new File(outname));
            System.out.println("...done, " + outname);
        } catch (Exception e) {
            e.printStackTrace();
        }
View Full Code Here

Examples of java.awt.image.BufferedImage

   */
  public static Image getInstance(java.awt.Image image, java.awt.Color color,
      boolean forceBW) throws BadElementException, IOException {
   
    if(image instanceof BufferedImage){
      BufferedImage bi = (BufferedImage) image;
      if(bi.getType()==BufferedImage.TYPE_BYTE_BINARY) {
        forceBW=true;
      }
    }
   
    java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(image,
View Full Code Here

Examples of java.awt.image.BufferedImage

     * @param cssWidth  Target width for the element.
     * @param cssHeight Target height for the element
     * @return A ReplacedElement to substitute for one that can't be generated.
     */
    protected ReplacedElement newIrreplaceableImageElement(int cssWidth, int cssHeight) {
        BufferedImage missingImage = null;
        ReplacedElement mre;
        try {
            // TODO: we can come up with something better; not sure if we should use Alt text, how text should size, etc.
            missingImage = ImageUtil.createCompatibleBufferedImage(cssWidth, cssHeight, BufferedImage.TYPE_INT_RGB);
            Graphics2D g = missingImage.createGraphics();
            g.setColor(Color.BLACK);
            g.setBackground(Color.WHITE);
            g.setFont(new Font("Serif", Font.PLAIN, 12));
            g.drawString("Missing", 0, 12);
            g.dispose();
View Full Code Here

Examples of java.awt.image.BufferedImage

        //TODO: check that cached image is still valid
        if (ir == null) {
            InputStream is = resolveAndOpenStream(uri);
            if (is != null) {
                try {
                    BufferedImage img = ImageIO.read(is);
                    if (img == null) {
                        throw new IOException("ImageIO.read() returned null");
                    }
                    ir = createImageResource(uri, img);
                    _imageCache.put(uri, ir);
View Full Code Here

Examples of java.awt.image.BufferedImage

        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);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.