java类java.awt.image.ImageProducer的实例源码

ImageProcessing.java 文件源码 项目:litiengine 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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);
}
ImagePreProcessor.java 文件源码 项目:mtgo-best-bot 阅读 23 收藏 0 点赞 0 评论 0
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);
}
WindowsLookAndFeel.java 文件源码 项目:OpenJSharp 阅读 18 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
WindowsLookAndFeel.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
WindowsLookAndFeel.java 文件源码 项目:openjdk-jdk10 阅读 22 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
TratadorDeImagens.java 文件源码 项目:brModelo 阅读 29 收藏 0 点赞 0 评论 0
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);
}
WindowsLookAndFeel.java 文件源码 项目:openjdk9 阅读 18 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
HelloWorld.java 文件源码 项目:yajsw 阅读 28 收藏 0 点赞 0 评论 0
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();
    }
}
WindowsLookAndFeel.java 文件源码 项目:jdk8u_jdk 阅读 18 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
AsyncImage.java 文件源码 项目:javify 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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;
    }
}
WindowsLookAndFeel.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 19 收藏 0 点赞 0 评论 0
/**
 * {@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);
}
Component.java 文件源码 项目:javify 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
XToolkit.java 文件源码 项目:javify 阅读 22 收藏 0 点赞 0 评论 0
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;
}
GtkImage.java 文件源码 项目:javify 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
}
GtkToolkit.java 文件源码 项目:javify 阅读 21 收藏 0 点赞 0 评论 0
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);
}
RotateFilter.java 文件源码 项目:VASSAL-src 阅读 34 收藏 0 点赞 0 评论 0
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);
}
ImageUtils.java 文件源码 项目:myfaces-trinidad 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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);
}
Component.java 文件源码 项目:OpenJSharp 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SimpleBeanInfo.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ToolkitImage.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
ToolkitImage.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
Component.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SimpleBeanInfo.java 文件源码 项目:jdk8u-jdk 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ToolkitImage.java 文件源码 项目:jdk8u-jdk 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
Component.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SimpleBeanInfo.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 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;
}
ToolkitImage.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Construct an image from an ImageProducer object.
 */
public ToolkitImage(ImageProducer is) {
    source = is;
    if (is instanceof InputStreamImageSource) {
        src = (InputStreamImageSource) is;
    }
}
ComponentOperator.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
/**
 * 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);
        }
    }));
}
Component.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SimpleBeanInfo.java 文件源码 项目:openjdk9 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 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;
}


问题


面经


文章

微信
公众号

扫码关注公众号