Added ImageUtil.createImage() to create blank images that are compatible
with the destination screen device. Updated existing code that previously created buffered images directly to reference ImageUtil. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@870 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileUtil.java,v 1.6 2001/12/17 03:33:41 mdb Exp $
|
// $Id: TileUtil.java,v 1.7 2002/01/18 17:48:11 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.cast.util;
|
package com.threerings.cast.util;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
|
import com.threerings.media.ImageUtil;
|
||||||
import com.threerings.media.sprite.MultiFrameImage;
|
import com.threerings.media.sprite.MultiFrameImage;
|
||||||
import com.threerings.media.sprite.Sprite;
|
import com.threerings.media.sprite.Sprite;
|
||||||
// import com.threerings.media.tile.*;
|
|
||||||
|
|
||||||
import com.threerings.cast.Log;
|
import com.threerings.cast.Log;
|
||||||
// import com.threerings.cast.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Miscellaneous tile-related utility functions.
|
* Miscellaneous tile-related utility functions.
|
||||||
@@ -73,9 +71,8 @@ public class TileUtil
|
|||||||
_images = new Image[frameCount];
|
_images = new Image[frameCount];
|
||||||
for (int i = 0; i < frameCount; i++) {
|
for (int i = 0; i < frameCount; i++) {
|
||||||
Image img = template.getFrame(i);
|
Image img = template.getFrame(i);
|
||||||
_images[i] = new BufferedImage(img.getWidth(null),
|
_images[i] = ImageUtil.createImage(
|
||||||
img.getHeight(null),
|
img.getWidth(null), img.getHeight(null));
|
||||||
BufferedImage.TYPE_INT_ARGB);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
//
|
//
|
||||||
// $Id: ImageUtil.java,v 1.1 2001/12/07 01:33:29 mdb Exp $
|
// $Id: ImageUtil.java,v 1.2 2002/01/18 17:48:11 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.media;
|
package com.threerings.media;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GraphicsConfiguration;
|
||||||
|
import java.awt.GraphicsDevice;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Transparency;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +23,12 @@ public class ImageUtil
|
|||||||
* image. If it is not, the subimage will be created and the data will
|
* image. If it is not, the subimage will be created and the data will
|
||||||
* be rendered into the newly created image.
|
* be rendered into the newly created image.
|
||||||
*
|
*
|
||||||
|
* @param source the source image.
|
||||||
|
* @param x the left coordinate of the sub-image.
|
||||||
|
* @param y the top coordinate of the sub-image.
|
||||||
|
* @param width the sub-image width.
|
||||||
|
* @param height the sub-image height.
|
||||||
|
*
|
||||||
* @return the desired subimage.
|
* @return the desired subimage.
|
||||||
*/
|
*/
|
||||||
public static Image getSubimage (
|
public static Image getSubimage (
|
||||||
@@ -28,8 +38,7 @@ public class ImageUtil
|
|||||||
return ((BufferedImage)source).getSubimage(x, y, width, height);
|
return ((BufferedImage)source).getSubimage(x, y, width, height);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
BufferedImage target =
|
BufferedImage target = createImage(width, height);
|
||||||
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics g = target.getGraphics();
|
Graphics g = target.getGraphics();
|
||||||
g.drawImage(source, 0, 0, width, height,
|
g.drawImage(source, 0, 0, width, height,
|
||||||
x, y, x+width, y+height, null);
|
x, y, x+width, y+height, null);
|
||||||
@@ -37,4 +46,50 @@ public class ImageUtil
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new blank, translucent image with the given dimensions.
|
||||||
|
* The format of the created image is compatible with the graphics
|
||||||
|
* configuration of the default screen device, such that no format
|
||||||
|
* conversion will be necessary when rendering the image to that
|
||||||
|
* device.
|
||||||
|
*
|
||||||
|
* @param width the desired image width.
|
||||||
|
* @param height the desired image height.
|
||||||
|
*
|
||||||
|
* @return the blank image.
|
||||||
|
*/
|
||||||
|
public static BufferedImage createImage (int width, int height)
|
||||||
|
{
|
||||||
|
return createImage(width, height, Transparency.TRANSLUCENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new blank image with the given dimensions and
|
||||||
|
* transparency. The format of the created image is compatible with
|
||||||
|
* the graphics configuration of the default screen device, such that
|
||||||
|
* no format conversion will be necessary when rendering the image to
|
||||||
|
* that device.
|
||||||
|
*
|
||||||
|
* @param width the desired image width.
|
||||||
|
* @param height the desired image height.
|
||||||
|
* @param transparency the desired image transparency; one of the
|
||||||
|
* constants in {@link java.awt.Transparency}.
|
||||||
|
*
|
||||||
|
* @return the blank image.
|
||||||
|
*/
|
||||||
|
public static BufferedImage createImage (
|
||||||
|
int width, int height, int transparency)
|
||||||
|
{
|
||||||
|
return _gc.createCompatibleImage(width, height, transparency);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The graphics configuration for the default screen device. */
|
||||||
|
protected static GraphicsConfiguration _gc;
|
||||||
|
static {
|
||||||
|
GraphicsEnvironment env =
|
||||||
|
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
|
GraphicsDevice gd = env.getDefaultScreenDevice();
|
||||||
|
_gc = gd.getDefaultConfiguration();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
//
|
//
|
||||||
// $Id: TileSet.java,v 1.23 2001/12/07 01:33:29 mdb Exp $
|
// $Id: TileSet.java,v 1.24 2002/01/18 17:48:11 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.media.tile;
|
package com.threerings.media.tile;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.Transparency;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.threerings.media.ImageUtil;
|
||||||
import com.threerings.media.Log;
|
import com.threerings.media.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,8 +189,7 @@ public abstract class TileSet
|
|||||||
protected Image createErrorImage (int width, int height)
|
protected Image createErrorImage (int width, int height)
|
||||||
{
|
{
|
||||||
// return a blank image for now
|
// return a blank image for now
|
||||||
return new BufferedImage(width, height,
|
return ImageUtil.createImage(width, height, Transparency.OPAQUE);
|
||||||
BufferedImage.TYPE_BYTE_INDEXED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user