Java Code Examples for java.awt.Image.getSource()

The following are Jave code examples for showing how to use getSource() of the java.awt.Image class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: litiengine   File: ImageProcessing.java   View Source Code Vote up 6 votes
/**
 * 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: brModelo   File: TratadorDeImagens.java   View Source Code Vote up 6 votes
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 3
Project: VASSAL-src   File: RotateFilter.java   View Source Code Vote up 5 votes
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 4
Project: myfaces-trinidad   File: OctreeQuantizer.java   View Source Code Vote up 5 votes
/**
 * Create a new octree and insert image data. This constructor is mostly
 * used by OctreeFilter.
 * @param im The image that provides pixel data to construct the tree
 */
public OctreeQuantizer(Image im)
{
  this();

  // first retrieve the pixels
  ImageLoader il = new ImageLoader(im);
  il.start();
  if(!il.waitFor()){
    throw new IllegalArgumentException(_LOG.getMessage(
      "PROBLEM_LOADING"));
  }
  int width = im.getWidth(il);
  int height = im.getHeight(il);
  int[] pixels = new int[width*height]; // going to hold all
  // the image's pixels
  
  PixelGrabber grabber = new PixelGrabber(im.getSource(), 0, 0,
                                          width, height,
                                          pixels, 0, width);
  try // get the pixels
  { 
    grabber.grabPixels();
  } 
  catch (InterruptedException e) 
  {
    throw new IllegalArgumentException(_LOG.getMessage(
      "GRABBING_PIXELS"));
  } 
  if ((grabber.getStatus() & ImageObserver.ABORT) != 0) 
  {
    throw new IllegalArgumentException(_LOG.getMessage(
      "ERROR_FETCHING_IMAGE", new Object[]{pixels.length,width,height}));
  }

  // add all pixels to the tree.
  for (int i = 0; i < pixels.length; i++)
    addColor(pixels[i]);

}
 
Example 5
Project: myfaces-trinidad   File: ImageUtils.java   View Source Code Vote up 5 votes
/**
 * 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 6
Project: openjdk-jdk10   File: ImageFilterTest.java   View Source Code Vote up 5 votes
public static void test(MyImageFilter testFilter) {
    Image image = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
    FilteredImageSource filtered =
            new FilteredImageSource(image.getSource(), testFilter);

    Image img = Toolkit.getDefaultToolkit().createImage(filtered);

    BufferedImage buffImage = new BufferedImage(img.getWidth(null),
            img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
}
 
Example 7
Project: incubator-netbeans   File: ImageUtilities.java   View Source Code Vote up 4 votes
static Image createDisabledImage(Image img) {
    ImageProducer prod = new FilteredImageSource(img.getSource(), DISABLED_BUTTON_FILTER);
    return Toolkit.getDefaultToolkit().createImage(prod);
}
 
Example 8
Project: OpenJSharp   File: MultiResolutionToolkitImage.java   View Source Code Vote up 4 votes
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
    super(lowResolutionImage.getSource());
    this.resolutionVariant = resolutionVariant;
}
 
Example 9
Project: jdk8u-jdk   File: MultiResolutionToolkitImage.java   View Source Code Vote up 4 votes
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
    super(lowResolutionImage.getSource());
    this.resolutionVariant = resolutionVariant;
}
 
Example 10
Project: openjdk-jdk10   File: MultiResolutionToolkitImage.java   View Source Code Vote up 4 votes
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
    super(lowResolutionImage.getSource());
    this.resolutionVariant = resolutionVariant;
}
 
Example 11
Project: OpenJSharp   File: PixelGrabber.java   View Source Code Vote up 3 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image.  The pixels are
 * accumulated in the original ColorModel if the same ColorModel
 * is used for every call to setPixels, otherwise the pixels are
 * accumulated in the default RGB ColorModel.  If the forceRGB
 * parameter is true, then the pixels will be accumulated in the
 * default RGB ColorModel anyway.  A buffer is allocated by the
 * PixelGrabber to hold the pixels in either case.  If {@code (w < 0)} or
 * {@code (h < 0)}, then they will default to the remaining width and
 * height of the source data when that information is delivered.
 * @param img the image to retrieve the image data from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param forceRGB true if the pixels should always be converted to
 * the default RGB ColorModel
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    boolean forceRGB)
{
    producer = img.getSource();
    dstX = x;
    dstY = y;
    dstW = w;
    dstH = h;
    if (forceRGB) {
        imageModel = ColorModel.getRGBdefault();
    }
}
 
Example 12
Project: jdk8u-jdk   File: PixelGrabber.java   View Source Code Vote up 3 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image.  The pixels are
 * accumulated in the original ColorModel if the same ColorModel
 * is used for every call to setPixels, otherwise the pixels are
 * accumulated in the default RGB ColorModel.  If the forceRGB
 * parameter is true, then the pixels will be accumulated in the
 * default RGB ColorModel anyway.  A buffer is allocated by the
 * PixelGrabber to hold the pixels in either case.  If {@code (w < 0)} or
 * {@code (h < 0)}, then they will default to the remaining width and
 * height of the source data when that information is delivered.
 * @param img the image to retrieve the image data from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param forceRGB true if the pixels should always be converted to
 * the default RGB ColorModel
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    boolean forceRGB)
{
    producer = img.getSource();
    dstX = x;
    dstY = y;
    dstW = w;
    dstH = h;
    if (forceRGB) {
        imageModel = ColorModel.getRGBdefault();
    }
}
 
Example 13
Project: openjdk-jdk10   File: PixelGrabber.java   View Source Code Vote up 3 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image.  The pixels are
 * accumulated in the original ColorModel if the same ColorModel
 * is used for every call to setPixels, otherwise the pixels are
 * accumulated in the default RGB ColorModel.  If the forceRGB
 * parameter is true, then the pixels will be accumulated in the
 * default RGB ColorModel anyway.  A buffer is allocated by the
 * PixelGrabber to hold the pixels in either case.  If {@code (w < 0)} or
 * {@code (h < 0)}, then they will default to the remaining width and
 * height of the source data when that information is delivered.
 * @param img the image to retrieve the image data from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param forceRGB true if the pixels should always be converted to
 * the default RGB ColorModel
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    boolean forceRGB)
{
    producer = img.getSource();
    dstX = x;
    dstY = y;
    dstW = w;
    dstH = h;
    if (forceRGB) {
        imageModel = ColorModel.getRGBdefault();
    }
}
 
Example 14
Project: OpenJSharp   File: PixelGrabber.java   View Source Code Vote up 2 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image into the given array.
 * The pixels are stored into the array in the default RGB ColorModel.
 * The RGB data for pixel (i, j) where (i, j) is inside the rectangle
 * (x, y, w, h) is stored in the array at
 * <tt>pix[(j - y) * scansize + (i - x) + off]</tt>.
 * @see ColorModel#getRGBdefault
 * @param img the image to retrieve pixels from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param pix the array of integers which are to be used to hold the
 * RGB pixels retrieved from the image
 * @param off the offset into the array of where to store the first pixel
 * @param scansize the distance from one row of pixels to the next in
 * the array
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    int[] pix, int off, int scansize) {
    this(img.getSource(), x, y, w, h, pix, off, scansize);
}
 
Example 15
Project: jdk8u-jdk   File: PixelGrabber.java   View Source Code Vote up 2 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image into the given array.
 * The pixels are stored into the array in the default RGB ColorModel.
 * The RGB data for pixel (i, j) where (i, j) is inside the rectangle
 * (x, y, w, h) is stored in the array at
 * <tt>pix[(j - y) * scansize + (i - x) + off]</tt>.
 * @see ColorModel#getRGBdefault
 * @param img the image to retrieve pixels from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param pix the array of integers which are to be used to hold the
 * RGB pixels retrieved from the image
 * @param off the offset into the array of where to store the first pixel
 * @param scansize the distance from one row of pixels to the next in
 * the array
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    int[] pix, int off, int scansize) {
    this(img.getSource(), x, y, w, h, pix, off, scansize);
}
 
Example 16
Project: openjdk-jdk10   File: PixelGrabber.java   View Source Code Vote up 2 votes
/**
 * Create a PixelGrabber object to grab the (x, y, w, h) rectangular
 * section of pixels from the specified image into the given array.
 * The pixels are stored into the array in the default RGB ColorModel.
 * The RGB data for pixel (i, j) where (i, j) is inside the rectangle
 * (x, y, w, h) is stored in the array at
 * {@code pix[(j - y) * scansize + (i - x) + off]}.
 * @see ColorModel#getRGBdefault
 * @param img the image to retrieve pixels from
 * @param x the x coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image, relative to the default
 * (unscaled) size of the image
 * @param y the y coordinate of the upper left corner of the rectangle
 * of pixels to retrieve from the image
 * @param w the width of the rectangle of pixels to retrieve
 * @param h the height of the rectangle of pixels to retrieve
 * @param pix the array of integers which are to be used to hold the
 * RGB pixels retrieved from the image
 * @param off the offset into the array of where to store the first pixel
 * @param scansize the distance from one row of pixels to the next in
 * the array
 */
public PixelGrabber(Image img, int x, int y, int w, int h,
                    int[] pix, int off, int scansize) {
    this(img.getSource(), x, y, w, h, pix, off, scansize);
}