public class MediaTools
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_AUDIO_PATH
The list of directories scanned for audio clips, separated by colons.
|
static java.lang.String |
DEFAULT_DATAFILE_PATH
The list of directories scanned for data files, separated by colons.
|
static java.lang.String |
DEFAULT_IMAGE_PATH
The list of directories scanned for images, separated by colons.
|
Modifier and Type | Method and Description |
---|---|
static void |
beep()
This method sounds the audible alert on the console, which is typically a
beep sound.
|
static java.awt.image.BufferedImage |
createBufferedImage(java.awt.Image image,
int type)
Creates a
BufferedImage from the specified image. |
static java.awt.Image |
createImage(java.io.InputStream in)
Generates an image from an input stream containing the data bytes for the
image formatted in image/gif format.
|
static java.awt.Image |
createImage(int[][] array)
Generates an image from a two-dimensional array of pixel values.
|
static java.awt.Image |
createImage(int[] pixels,
int width,
int height)
Generates an image from a single-dimensional array of pixel values.
|
static java.awt.Image |
createImage(java.lang.String[] hexData)
Generates an image from a string array that provides the pixel values.
|
static java.awt.Image |
createPSPreviewImage(java.awt.Image image,
java.lang.String[] preview)
Creates a new image that combines an existing image with a PostScript preview
represented as a string array.
|
static void |
defineImage(java.lang.String name,
java.awt.Image image)
Inserts the given image into the image table under the specified name.
|
static void |
flushImage(java.lang.String name)
Removes the image with the given name from the cache, allowing it to be freed
by the garbage collector.
|
static java.io.InputStream |
getHexInputStream(java.lang.String[] hexData)
Returns an input stream whose bytes come from the string array
hex , in which the elements consist of continuous bytes of hex
data. |
static java.awt.Component |
getImageObserver()
This method returns a new lightweight component suitable as an
imageObserver . |
static int[][] |
getPixelArray(java.awt.Image image)
Returns a two-dimensional array of the pixels in the image.
|
static boolean |
isCachingEnabled()
This method returns the status of the flag that determins whether images and
audio clips are cached internally by name, as described in
setCachingEnabled . |
static java.awt.Image |
loadImage(java.awt.Image image)
Makes sure that the image is fully loaded before returning.
|
static java.awt.Image |
loadImage(java.lang.String name)
Searches the default image search path for an image with the specified name
and then loads it to create an
Image . |
static java.awt.Image |
loadImage(java.lang.String name,
java.lang.String path)
Searches for an image with the given name and loads it to create an
Image . |
static java.awt.Image |
loadImage(java.net.URL url)
Loads an image from the specified URL.
|
static java.awt.Image |
loadImage(java.net.URL url,
boolean topLevel)
Loads an image from the specified URL.
|
static java.io.InputStream |
openDataFile(java.lang.String name)
Searches the default datafile search path for a file with the specified name
and then opens it to create an
InputStream . |
static java.io.InputStream |
openDataFile(java.lang.String name,
java.lang.String path)
Searches for a data file with the given name and opens it to create an
InputStream . |
static java.io.InputStream |
openDataFile(java.net.URL url)
Opens the specified URL to create an
InputStream . |
static java.io.InputStream |
openDataFile(java.net.URL url,
boolean topLevel)
Opens a data file using the specified URL.
|
static void |
saveImage(java.awt.Image image,
java.io.File file)
Saves an image to the specified file.
|
static void |
saveImage(java.awt.Image image,
java.lang.String filename)
Saves an image to a file with the specified filename.
|
static void |
setCachingEnabled(boolean flag)
This method sets an internal flag in the
MediaTools package to
indicate whether images and audio clips are cached internally by name. |
public static final java.lang.String DEFAULT_IMAGE_PATH
public static final java.lang.String DEFAULT_AUDIO_PATH
public static final java.lang.String DEFAULT_DATAFILE_PATH
public static java.awt.Image loadImage(java.lang.String name)
Image
. The search process
consists of the following steps:
Image
. If so, read the image from the
resource file.
The second and third steps are repeated for each element of the image search path, which consists of a list of directories separated by colons.
Unlike the getImage
method in the Applet
class,
loadImage
waits for an image to be fully loaded before
returning.
name
- The name of the imageImage
objectpublic static java.awt.Image loadImage(java.lang.String name, java.lang.String path)
Image
. Its operation is identical to the single-argument
loadImage
call except in that
this version allows the client to specify the search path explicitly.name
- The name of the imagepath
- A string of directories names separated by colonsImage
objectpublic static java.awt.Image loadImage(java.net.URL url)
url
- The url containing the imageImage
objectpublic static java.awt.Image loadImage(java.awt.Image image)
image
- The Image
which may not yet be loadedImage
after ensuring that it is fully loadedpublic static void defineImage(java.lang.String name, java.awt.Image image)
name
- The name for the imageimage
- The image to be stored in the tablepublic static void flushImage(java.lang.String name)
name
- The name for the imagepublic static java.awt.Image createImage(int[][] array)
array
- A two-dimensional array of int
s representing the
pixelsImage
objectpublic static java.awt.Image createImage(int[] pixels, int width, int height)
pixels
- An array of int
s representing the pixelswidth
- The width of the imageheight
- The height of the imageImage
objectpublic static java.awt.Image createImage(java.io.InputStream in)
in
- An input stream containing the dataImage
objectpublic static java.awt.Image createImage(java.lang.String[] hexData)
hexData
- A hex string array representing a .gif valueImage
objectpublic static int[][] getPixelArray(java.awt.Image image)
image
- The imagepublic static void saveImage(java.awt.Image image, java.lang.String filename)
image
- The imagefilename
- The name of the file to which the image is savedpublic static void saveImage(java.awt.Image image, java.io.File file)
image
- The imagefile
- The File
to which the image is savedpublic static java.awt.Image createPSPreviewImage(java.awt.Image image, java.lang.String[] preview)
"PSPreview"
property.image
- The original imagepreview
- The corresponding PostScript previewpublic static java.io.InputStream openDataFile(java.lang.String name)
InputStream
. The search process
consists of the following steps:
InputStream
open on that resource.
These steps are repeated for each element of the datafile search path, which consists of a list of directories separated by colons.
name
- The name of the input fileInputStream
open on the specified filepublic static java.io.InputStream openDataFile(java.lang.String name, java.lang.String path)
InputStream
. Its operation is identical to the single-argument
openDataFile
call except in
that this version allows the client to specify the search path explicitly.name
- The name of the audio clippath
- A string of directories names separated by colonsInputStream
open on the specified filepublic static java.io.InputStream openDataFile(java.net.URL url)
InputStream
.url
- The URL of the data fileInputStream
open on the specified URLpublic static java.awt.image.BufferedImage createBufferedImage(java.awt.Image image, int type)
BufferedImage
from the specified image. The
type
parameter is used to specify the image type, as described
in the BufferedImage
documentation.image
- The original imagetype
- The type code used to describe the image modelA
- BufferedImage
containing the image datapublic static java.io.InputStream getHexInputStream(java.lang.String[] hexData)
hex
, in which the elements consist of continuous bytes of hex
data.hexData
- An array of strings specifying a byte stream coded in hexpublic static void setCachingEnabled(boolean flag)
MediaTools
package to
indicate whether images and audio clips are cached internally by name. This
flag is disabled by default.flag
- true
to enable caching by name, false
to disable it.public static boolean isCachingEnabled()
setCachingEnabled
.true
if caching by name is enabled, false
otherwise.public static java.awt.Component getImageObserver()
imageObserver
.imageObserver
.public static void beep()
public static java.awt.Image loadImage(java.net.URL url, boolean topLevel)
topLevel
flag is
false
if this is invoked internally.public static java.io.InputStream openDataFile(java.net.URL url, boolean topLevel)
topLevel
flag is
false
if this is invoked internally.