The image manager now falls back to loading images via the Toolkit if it
can't load the ImageIO classes. This unfortunately means that we're back to passing a Component instance to the ImageManager at construct time. Whee! git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@749 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// $Id: ImageUtil.java,v 1.1 2001/12/07 01:33:29 mdb Exp $
|
||||
|
||||
package com.threerings.media;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Image related utility functions.
|
||||
*/
|
||||
public class ImageUtil
|
||||
{
|
||||
/**
|
||||
* Extracts a subimage from the supplied image with the specified
|
||||
* dimensions. If the supplied image is an instance of {@link
|
||||
* BufferedImage}, then the subimage will simply reference the main
|
||||
* image. If it is not, the subimage will be created and the data will
|
||||
* be rendered into the newly created image.
|
||||
*
|
||||
* @return the desired subimage.
|
||||
*/
|
||||
public static Image getSubimage (
|
||||
Image source, int x, int y, int width, int height)
|
||||
{
|
||||
if (source instanceof BufferedImage) {
|
||||
return ((BufferedImage)source).getSubimage(x, y, width, height);
|
||||
|
||||
} else {
|
||||
BufferedImage target =
|
||||
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = target.getGraphics();
|
||||
g.drawImage(source, 0, 0, width, height,
|
||||
x, y, x+width, y+height, null);
|
||||
g.dispose();
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user