下面列出了java.awt.Image#getSource() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
super(lowResolutionImage.getSource());
this.resolutionVariant = resolutionVariant;
}
public static Image filterImage(final Image inImage, final ImageFilter filter) {
final ImageProducer imageProducer = new FilteredImageSource(inImage.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(imageProducer);
}
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
super(lowResolutionImage.getSource());
this.resolutionVariant = resolutionVariant;
}
private Image filterImage(Image sourceImage, ImageFilter imageFilter) {
ImageProducer ip = new FilteredImageSource(sourceImage.getSource(), imageFilter);
return Toolkit.getDefaultToolkit().createImage(ip);
}
protected static BufferedImage createImage(Image i, String description) {
ImageLoader l = new ImageLoader(i.getSource(), null, null, description);
return l.getImage();
}
private BufferedImage createGhostImage(Image image) {
ImageFilter filter = new GrayFilter(true, 50);
ImageProducer producer = new FilteredImageSource(image.getSource(), filter);
Image toolkitImage = Toolkit.getDefaultToolkit().createImage(producer);
return ImageUtils.toBufferedImage(toolkitImage);
}
public MultiResolutionToolkitImage(Image lowResolutionImage, Image resolutionVariant) {
super(lowResolutionImage.getSource());
this.resolutionVariant = resolutionVariant;
}
/**
* 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();
}
}
/**
* 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();
}
}
/**
* 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 (w < 0) or
* (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();
}
}
/**
* 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();
}
}
/**
* 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();
}
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}
/**
* 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);
}