Java Code Examples for java.awt.image.ImageProducer

The following are top voted examples for showing how to use java.awt.image.ImageProducer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: litiengine   File: ImageProcessing.java   Source Code and License 6 votes vote down vote up
/**
 * All pixels that have the specified color are rendered transparent.
 *
 * @param img
 *          the img
 * @param color
 *          the color
 * @return the image
 */
public static Image applyAlphaChannel(final Image img, final Color color) {
  if (color == null || img == null) {
    return img;
  }

  final ImageFilter filter = new RGBImageFilter() {

    // the color we are looking for... Alpha bits are set to opaque
    public final int markerRGB = color.getRGB() | 0xFF000000;

    @Override
    public final int filterRGB(final int x, final int y, final int rgb) {
      if ((rgb | 0xFF000000) == this.markerRGB) {
        // Mark the alpha bits as zero - transparent
        return 0x00FFFFFF & rgb;
      } else {
        // nothing to do
        return rgb;
      }
    }
  };

  final ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
  return Toolkit.getDefaultToolkit().createImage(ip);
}
 
Example 2
Project: mtgo-best-bot   File: ImagePreProcessor.java   Source Code and License 6 votes vote down vote up
public BufferedImage getGrayscaledImage(BufferedImage coloredImage) {
    ImageFilter filter = new ImageFilter(){
        public final int filterRGB(int x, int y, int rgb)
        {
            //TODO - optimization? Bit shifts, not this shits
            Color currentColor = new Color(rgb);
            if(currentColor.getRed() < 2 && currentColor.getGreen() < 2 && currentColor.getBlue() < 2) {
                return new Color(rgb).darker().getRGB();
            }

            return Color.WHITE.getRGB();
        }
    };

    ImageProducer producer = new FilteredImageSource(coloredImage.getSource(), filter);
    Image image = Toolkit.getDefaultToolkit().createImage(producer);
    return toBufferedImage(image);
}
 
Example 3
Project: OpenJSharp   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 4
Project: jdk8u-jdk   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 5
Project: openjdk-jdk10   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 6
Project: brModelo   File: TratadorDeImagens.java   Source Code and License 6 votes vote down vote up
public static Image makeColorTransparent(Image im, final Color color) {
    //(C)
    //Copiado da internet: 13/02/2011 - http://www.rgagnon.com/javadetails/java-0265.html e http://www.coderanch.com/t/331731/GUI/java/Resize-ImageIcon
    //

    ImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque

        public int markerRGB = color.getRGB() | 0xFF000000;

        @Override
        public final int filterRGB(int x, int y, int rgb) {
            if ((rgb | 0xFF000000) == markerRGB) {
                // Mark the alpha bits as zero - transparent
                return 0x00FFFFFF & rgb;
            } else {
                // nothing to do
                return rgb;
            }
        }
    };

    ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}
 
Example 7
Project: openjdk9   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 8
Project: yajsw   File: HelloWorld.java   Source Code and License 6 votes vote down vote up
private static void startTray()
{
	SystemTray tray = SystemTray.getSystemTray();
	int w = 80;
	int[] pix = new int[w * w];
	for (int i = 0; i < w * w; i++)
		pix[i] = (int) (Math.random() * 255);
	ImageProducer producer = new MemoryImageSource(w, w, pix, 0, w);
	Image image = Toolkit.getDefaultToolkit().createImage(producer);
	TrayIcon trayIcon = new TrayIcon(image);
	trayIcon.setImageAutoSize(true);
	startWindow();
	try
	{
		tray.add(trayIcon);
		System.out.println("installed tray");
	}
	catch (AWTException e)
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 9
Project: jdk8u_jdk   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 10
Project: javify   File: AsyncImage.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the real image source, if already present. Otherwise, this
 * returns <code>null</code>.
 *
 * @return the real image source, or <code>null</code> if not present
 */
private ImageProducer getRealSource()
{
  synchronized (AsyncImage.this)
    {
      ImageProducer source = realSource;
      if (source == null)
        {
          Image ri = realImage;
          if (ri != null)
            {
              realSource = source = ri.getSource();
            }
        }
      return source;
    }
}
 
Example 11
Project: lookaside_java-1.8.0-openjdk   File: WindowsLookAndFeel.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @since 1.6
 */
public Icon getDisabledIcon(JComponent component, Icon icon) {
    // if the component has a HI_RES_DISABLED_ICON_CLIENT_KEY
    // client property set to Boolean.TRUE, then use the new
    // hi res algorithm for creating the disabled icon (used
    // in particular by the WindowsFileChooserUI class)
    if (icon != null
            && component != null
            && Boolean.TRUE.equals(component.getClientProperty(HI_RES_DISABLED_ICON_CLIENT_KEY))
            && icon.getIconWidth() > 0
            && icon.getIconHeight() > 0) {
        BufferedImage img = new BufferedImage(icon.getIconWidth(),
                icon.getIconWidth(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
        ImageFilter filter = new RGBGrayFilter();
        ImageProducer producer = new FilteredImageSource(img.getSource(), filter);
        Image resultImage = component.createImage(producer);
        return new ImageIconUIResource(resultImage);
    }
    return super.getDisabledIcon(component, icon);
}
 
Example 12
Project: javify   File: Component.java   Source Code and License 6 votes vote down vote up
/**
 * Creates an image from the specified producer.
 *
 * @param producer the image procedure to create the image from
 * @return the resulting image
 */
public Image createImage(ImageProducer producer)
{
  // Only heavyweight peers can handle this.
  ComponentPeer p = peer;
  Component comp = this;
  while (p instanceof LightweightPeer)
    {
      comp = comp.parent;
      p = comp == null ? null : comp.peer;
    }

  // Sun allows producer to be null.
  Image im;
  if (p != null)
    im = p.createImage(producer);
  else
    im = getToolkit().createImage(producer);
  return im;
}
 
Example 13
Project: javify   File: XToolkit.java   Source Code and License 6 votes vote down vote up
private Image createImage(InputStream i)
  throws IOException
{
  Image image;
  BufferedImage buffered = ImageIO.read(i);
  // If the bufferedimage is opaque, then we can copy it over to an
  // X Pixmap for faster drawing.
  if (buffered != null && buffered.getTransparency() == Transparency.OPAQUE)
    {
      ImageProducer source = buffered.getSource();
      image = createImage(source);
    }
  else if (buffered != null)
    {
      image = buffered;
    }
  else
    {
      image = createErrorImage();
    }
  return image;
}
 
Example 14
Project: javify   File: GtkImage.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the source of this image.
 */
public ImageProducer getSource ()
{
  if (!isLoaded)
    return null;

  int[] pixels;
  synchronized (pixbufLock)
    {
      if (!errorLoading)
        pixels = getPixels();
      else
        return null;
    }
  return new MemoryImageSource(width, height, nativeModel, pixels,
                               0, width);
}
 
Example 15
Project: javify   File: GtkToolkit.java   Source Code and License 6 votes vote down vote up
public Image createImage (ImageProducer producer)
{
  if (producer == null)
    return null;

  Image image;
  try
    {
      image = CairoSurface.getBufferedImage( new GtkImage( producer ) );
    }
  catch (IllegalArgumentException iae)
    {
      image = null;
    }
  return imageOrError(image);
}
 
Example 16
Project: VASSAL-src   File: RotateFilter.java   Source Code and License 5 votes vote down vote up
public static void main(String args[]) {
  final Image unrotated = Toolkit.getDefaultToolkit().getImage("ASL/images/Climb1d.gif");

  ImageFilter filter = new RotateFilter(-60.0);
  ImageProducer producer = new FilteredImageSource(unrotated.getSource(), filter);
  final Image rotated = new javax.swing.JLabel().createImage(producer);
  javax.swing.JFrame f = new javax.swing.JFrame() {
    private static final long serialVersionUID = 1L;

    public void paint(Graphics g) {
      g.setColor(Color.blue);
      g.fillRect(0, 0, getSize().width, getSize().height);
      g.drawImage(rotated, 100, 100, this);
      g.drawImage(unrotated, 0, 0, this);
      g.drawImage(unrotated,
                  100 + unrotated.getWidth(this),
                  unrotated.getHeight(this),
                  100, 0,
                  0, 0,
                  0 + unrotated.getWidth(this),
                  unrotated.getHeight(this),
                  this);
    }
  };
  f.setSize(300, 300);
  f.setVisible(true);
}
 
Example 17
Project: myfaces-trinidad   File: ImageUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Given an image and a filter, creates the resulting image.
 * @param baseImage the base image
 * @param imageFilter the image filter
 */
public static Image createFilteredImage(
  Image       baseImage,
  ImageFilter imageFilter
  )
{
  // get the filtered image producer
  ImageProducer producer = new FilteredImageSource(baseImage.getSource(),
                                                   imageFilter);

  // return the filtered image
  return Toolkit.getDefaultToolkit().createImage(producer);
}
 
Example 18
Project: OpenJSharp   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     JDK1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 19
Project: OpenJSharp   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 20
Project: OpenJSharp   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 21
Project: OpenJSharp   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 22
Project: jdk8u-jdk   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     JDK1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 23
Project: jdk8u-jdk   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 24
Project: jdk8u-jdk   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 25
Project: openjdk-jdk10   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 26
Project: openjdk-jdk10   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images. It takes the
 * name of a resource file associated with the current object's class file
 * and loads an image object from that file. Typically images will be GIFs.
 *
 * @param  resourceName A pathname relative to the directory holding the
 *         class file of the current class. For example, "wombat.gif".
 * @return an image object or null if the resource is not found or the
 *         resource could not be loaded as an Image
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 27
Project: openjdk-jdk10   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 28
Project: openjdk-jdk10   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.createImage(ImageProducer)} through queue
 */
public Image createImage(final ImageProducer imageProducer) {
    return (runMapping(new MapAction<Image>("createImage") {
        @Override
        public Image map() {
            return getSource().createImage(imageProducer);
        }
    }));
}
 
Example 29
Project: openjdk9   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 30
Project: openjdk9   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images. It takes the
 * name of a resource file associated with the current object's class file
 * and loads an image object from that file. Typically images will be GIFs.
 *
 * @param  resourceName A pathname relative to the directory holding the
 *         class file of the current class. For example, "wombat.gif".
 * @return an image object or null if the resource is not found or the
 *         resource could not be loaded as an Image
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 31
Project: openjdk9   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 32
Project: openjdk9   File: ComponentOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Component.createImage(ImageProducer)} through queue
 */
public Image createImage(final ImageProducer imageProducer) {
    return (runMapping(new MapAction<Image>("createImage") {
        @Override
        public Image map() {
            return getSource().createImage(imageProducer);
        }
    }));
}
 
Example 33
Project: Java8CN   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     JDK1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 34
Project: Java8CN   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 35
Project: melon   File: ScreenCapture.java   Source Code and License 5 votes vote down vote up
protected void do_button_actionPerformed(ActionEvent e) {
    try {
        Robot robot = new Robot();// 创建Robot对象
        Toolkit toolkit = Toolkit.getDefaultToolkit();// 获得Toolkit对象
        Rectangle area = new Rectangle(toolkit.getScreenSize());// 设置截取区域为全屏
        // 将BufferedImage转换成Image
        BufferedImage bufferedImage = robot.createScreenCapture(area);
        ImageProducer producer = bufferedImage.getSource();
        Image image = toolkit.createImage(producer);
        imageLabel.setIcon(new ImageIcon(image));// 显示图片
    } catch (AWTException e1) {
        e1.printStackTrace();
    }
}
 
Example 36
Project: pumpernickel   File: GenericImageSinglePassIterator.java   Source Code and License 5 votes vote down vote up
/** Returns a <code>GenericImageSinglePassIterator</code> that is
 * either a <code>IntPixelIterator</code> or a <code>BytePixelIterator</code>.
 * @param image the image to iterate over.
 * @param iteratorType one of these 8 BufferedImage types:
 * TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_RGB, TYPE_INT_BGR,
 * TYPE_3BYTE_BGR, TYPE_BYTE_GRAY, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE.
 * @return a <code>GenericImageSinglePassIterator</code> for the image provided.
 */
public static GenericImageSinglePassIterator get(Image image,int iteratorType) {
	if(!(iteratorType==BufferedImage.TYPE_INT_ARGB ||
			iteratorType==BufferedImage.TYPE_INT_ARGB_PRE ||
			iteratorType==BufferedImage.TYPE_INT_RGB ||
			iteratorType==BufferedImage.TYPE_INT_BGR ||
			iteratorType==BufferedImage.TYPE_3BYTE_BGR ||
			iteratorType==BufferedImage.TYPE_BYTE_GRAY ||
			iteratorType==BufferedImage.TYPE_4BYTE_ABGR ||
			iteratorType==BufferedImage.TYPE_4BYTE_ABGR_PRE)) {
		throw new IllegalArgumentException("illegal iterator type: "+iteratorType);
	}
	final ImageProducer producer = image.getSource();
	final Consumer consumer = new Consumer(producer, iteratorType);
	// ImageProducer.startProduction often starts its own thread, but it's not
	// required to.  Sometimes in my testing a BufferedImage would make
	// this a blocking call.  So to be safe this call should be in its
	// own thread:
	Thread productionThread = new Thread("GenericImageSinglePassIterator: Production Thread") {
		@Override
		public void run() {
			producer.startProduction(consumer);
		}
	};
	productionThread.start();
	return consumer.getPixelIterator();
}
 
Example 37
Project: jdk8u_jdk   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     JDK1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 38
Project: jdk8u_jdk   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 39
Project: jdk8u_jdk   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 40
Project: lookaside_java-1.8.0-openjdk   File: Component.java   Source Code and License 5 votes vote down vote up
/**
 * Creates an image from the specified image producer.
 * @param     producer  the image producer
 * @return    the image produced
 * @since     JDK1.0
 */
public Image createImage(ImageProducer producer) {
    ComponentPeer peer = this.peer;
    if ((peer != null) && ! (peer instanceof LightweightPeer)) {
        return peer.createImage(producer);
    }
    return getToolkit().createImage(producer);
}
 
Example 41
Project: lookaside_java-1.8.0-openjdk   File: SimpleBeanInfo.java   Source Code and License 5 votes vote down vote up
/**
 * This is a utility method to help in loading icon images.
 * It takes the name of a resource file associated with the
 * current object's class file and loads an image object
 * from that file.  Typically images will be GIFs.
 * <p>
 * @param resourceName  A pathname relative to the directory
 *          holding the class file of the current class.  For example,
 *          "wombat.gif".
 * @return  an image object.  May be null if the load failed.
 */
public Image loadImage(final String resourceName) {
    try {
        final URL url = getClass().getResource(resourceName);
        if (url != null) {
            final ImageProducer ip = (ImageProducer) url.getContent();
            if (ip != null) {
                return Toolkit.getDefaultToolkit().createImage(ip);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
 
Example 42
Project: lookaside_java-1.8.0-openjdk   File: ToolkitImage.java   Source Code and License 5 votes vote down vote up
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
 
Example 43
Project: JavaAyo   File: GifJpgConverter.java   Source Code and License 5 votes vote down vote up
public static void toJPG(String source, String dest, int quality) {  

    if (dest == null || dest.trim().equals(""))  
        dest = source;  
  
    if (!dest.toLowerCase().trim().endsWith("jpg")) {  
        dest += ".jpg";  
        System.out.println("Overriding to JPG, output file: " + dest);  
    }  
      
      
    if (quality < 0 || quality > 100 || (quality + "") == null || (quality + "").equals("")) {  
        quality = 75;  
    }  
      
    try {  
        JPGOptions options = new JPGOptions();  
        options.setQuality(quality);  
        ImageProducer image = Jimi.getImageProducer(source);  
        JimiWriter writer = Jimi.createJimiWriter(dest);  
        writer.setSource(image);  
        writer.setOptions(options);  
        writer.putImage(dest);  
    } catch (JimiException je) {  
        System.err.println("Error: " + je);  
    }  
}
 
Example 44
Project: javify   File: AbstractGraphics2D.java   Source Code and License 5 votes vote down vote up
/**
 * Scales an image to the specified width and height. This should also
 * be used to implement
 * {@link Toolkit#prepareImage(Image, int, int, ImageObserver)}.
 * This uses {@link Toolkit#createImage(ImageProducer)} to create the actual
 * image.
 *
 * @param image the image to prepare
 * @param w the width
 * @param h the height
 *
 * @return the scaled image
 */
public static Image prepareImage(Image image, int w, int h)
{
  // Try to find cached scaled image.
  HashMap<Dimension,Image> scaledTable = imageCache.get(image);
  Dimension size = new Dimension(w, h);
  Image scaled = null;
  if (scaledTable != null)
    {
      scaled = scaledTable.get(size);
    }
  if (scaled == null)
    {
      // No cached scaled image. Start scaling image now.
      ImageProducer source = image.getSource();
      ReplicateScaleFilter scaler = new ReplicateScaleFilter(w, h);
      FilteredImageSource filteredSource =
        new FilteredImageSource(source, scaler);
      // Ideally, this should asynchronously scale the image.
      Image scaledImage =
        Toolkit.getDefaultToolkit().createImage(filteredSource);
      scaled = scaledImage;
      // Put scaled image in cache.
      if (scaledTable == null)
        {
          scaledTable = new HashMap<Dimension,Image>();
          imageCache.put(image, scaledTable);
        }
      scaledTable.put(size, scaledImage);
    }
  return scaled;
}
 
Example 45
Project: javify   File: XToolkit.java   Source Code and License 5 votes vote down vote up
public Image createImage(ImageProducer producer)
{
  ImageConverter conv = new ImageConverter();
  producer.startProduction(conv);
  Image image = conv.getImage();
  return image;
}
 
Example 46
Project: javify   File: BufferedImageGraphics.java   Source Code and License 5 votes vote down vote up
protected boolean drawImage(Image img, AffineTransform xform,
                            Color bgcolor, ImageObserver obs)
{
  if (comp == null || comp instanceof AlphaComposite)
    {
      boolean rv = super.drawImage(img, xform, bgcolor, obs);
      updateBufferedImage(0, 0, imageWidth, imageHeight);
      return rv;
    }
  else
    {
      // Get buffered image of source
      if( !(img instanceof BufferedImage) )
        {
          ImageProducer source = img.getSource();
          if (source == null)
            return false;
          img = Toolkit.getDefaultToolkit().createImage(source);
        }
      BufferedImage bImg = (BufferedImage) img;

      // Find translated bounds
      Rectangle2D bounds = new Rectangle(bImg.getMinX(), bImg.getMinY(),
                                         bImg.getWidth(), bImg.getHeight());
      if (xform != null)
        bounds = getTransformedBounds(bounds, xform);

      // Create buffer and draw image
      createBuffer();

      Graphics2D g2d = (Graphics2D)buffer.getGraphics();
      g2d.setRenderingHints(this.getRenderingHints());
      g2d.drawImage(img, xform, obs);

      // Perform compositing
      return drawComposite(bounds, obs);
    }
}
 
Example 47
Project: javify   File: AsyncImage.java   Source Code and License 5 votes vote down vote up
public ImageProducer getSource()
{
  Image r = realImage;
  ImageProducer source;
  if (r == null)
    source = new NullImageSource();
  else
    source = r.getSource();
  return source;
}
 
Example 48
Project: javify   File: GtkImage.java   Source Code and License 5 votes vote down vote up
/**
 * Constructs a GtkImage from an ImageProducer. Asynchronity is handled in
 * the following manner:
 * A GtkImageConsumer gets the image data, and calls setImage() when
 * completely finished. The GtkImage is not considered loaded until the
 * GtkImageConsumer is completely finished. We go for all "all or nothing".
 */
public GtkImage (ImageProducer producer)
{
  isLoaded = false;
  observers = new Vector<ImageObserver>();
  source = producer;
  errorLoading = false;
  source.startProduction(new GtkImageConsumer(this, source));
}
 
Example 49
Project: pathvisio   File: ColorByExpression.java   Source Code and License 5 votes vote down vote up
Image doReplaceColor(Image img, final Color oldColor, final Color newColor, final int tol) {
	RGBImageFilter f = new RGBImageFilter() {
		public int filterRGB(int x, int y, int rgb) {
			Color thisColor = new Color(rgb);
			if(compareColor(oldColor, thisColor, tol)) {
				return newColor.getRGB();
			}
			return rgb;
		}
	};
	ImageProducer pr = new FilteredImageSource(img.getSource(), f);
	return Toolkit.getDefaultToolkit().createImage(pr);
}
 
Example 50
Project: javify   File: QtImage.java   Source Code and License 5 votes vote down vote up
/**
 * Creates the image from an ImageProducer. May result in an error image.
 */
public QtImage (ImageProducer producer)
{
  killFlag = false;
  isLoaded = false;
  observers = new Vector();
  source = producer;
  errorLoading = false;
  if( producer != null )
    source.startProduction(new QtImageConsumer(this, source));
}
 
Example 51
Project: javify   File: QtImage.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the source of this image.
 */
public ImageProducer getSource ()
{
  if (!isLoaded)
    return null;
  return new MemoryImageSource(width, height, nativeModel, getPixels(),
                               0, width);
}
 
Example 52
Project: incubator-netbeans   File: ImageUtilities.java   Source Code and License 4 votes vote down vote up
static Image createDisabledImage(Image img) {
    ImageProducer prod = new FilteredImageSource(img.getSource(), DISABLED_BUTTON_FILTER);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
 
Example 53
Project: incubator-netbeans   File: UtilitiesTest.java   Source Code and License 4 votes vote down vote up
public Image createImage(ImageProducer producer) {
    return Toolkit.getDefaultToolkit().createImage( producer );
}
 
Example 54
Project: incubator-netbeans   File: CImage.java   Source Code and License 4 votes vote down vote up
public ImageProducer getSource() {
    System.err.println("GET SOURCE");
    Thread.dumpStack();
    return null;
}
 
Example 55
Project: OpenJSharp   File: NullComponentPeer.java   Source Code and License 4 votes vote down vote up
public Image createImage(ImageProducer producer) {
    return null;
}
 
Example 56
Project: OpenJSharp   File: ToolkitImage.java   Source Code and License 4 votes vote down vote up
public ImageProducer getSource() {
    if (src != null) {
        src.checkSecurity(null, false);
    }
    return source;
}
 
Example 57
Project: OpenJSharp   File: OffScreenImage.java   Source Code and License 4 votes vote down vote up
public ImageProducer getSource() {
    if (osis == null) {
        osis = new OffScreenImageSource(this);
    }
    return osis;
}
 
Example 58
Project: OpenJSharp   File: LWComponentPeer.java   Source Code and License 4 votes vote down vote up
@Override
public final Image createImage(final ImageProducer producer) {
    return new ToolkitImage(producer);
}
 
Example 59
Project: OpenJSharp   File: WComponentPeer.java   Source Code and License 4 votes vote down vote up
@Override
public Image createImage(ImageProducer producer) {
    return new ToolkitImage(producer);
}
 
Example 60
Project: OpenJSharp   File: XComponentPeer.java   Source Code and License 4 votes vote down vote up
public Image createImage(ImageProducer producer) {
    return new ToolkitImage(producer);
}