JavaView® v2.12

jv.objectGui
Class PsImage

java.lang.Object
  |
  +--jv.objectGui.PsImage

public class PsImage
extends java.lang.Object

A class for loading and handling images.

Version:
18.01.00, 1.01 revised (kp) Changed superclass from PsObject to java.lang.Object.
02.01.99, 1.00 created (kp).
Author:
Konrad Polthier

Constructor Summary
PsImage(java.awt.Image anImage, java.lang.String alternateText)
          Create an PsImage using the image specified.
PsImage(java.lang.String imageName)
          Create an PsImage using the image at relative path specified by the string.
PsImage(java.net.URL url)
          Create an PsImage using the image at an absolute URL specified by the string.
 
Method Summary
static java.awt.Image createImageFromPixels(java.awt.Component comp, int[] pixels, int width, int height, int offset, int scan)
          Load image with a media tracker and return when image is loaded or failure occurred.
 int getHeight()
          Get height of loaded image.
 java.awt.Image getImage()
          Get the image after loading it if not done yet.
static java.awt.Image getImage(java.lang.String imageName)
          Get image relative to codeBase of applet, or from file system.
static java.awt.Image getImage(java.net.URL url)
          Get image from absolute URL.
static PsImage getImageFromArchive(java.lang.String imageName, java.lang.String jarArchive)
          Get an image from a jar archive.
static int[] getPixels(java.awt.Image image)
          Convert an image to an array of pixels.
static int[] getPixels(java.awt.Image image, int x, int y, int width, int height, int[] pixels, int off, int scan)
           
 int getWidth()
          Get width of loaded image.
 void init()
          Create MediaTracker.
 boolean loadImage()
          Makes sure that the Image is loaded before returning from this method.
static boolean loadImage(java.awt.Component comp, java.awt.Image image)
          Load image with a media tracker and return when image is loaded or failure occurred.
 void setParentComponent(java.awt.Component comp)
          Set component used for MediaTracker in init() method
 void setSize(int width, int height)
          Resizes the image after loading it if not done yet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PsImage

public PsImage(java.net.URL url)
Create an PsImage using the image at an absolute URL specified by the string.
Parameters:
url - A String specifying the absolute URL of the image.

PsImage

public PsImage(java.lang.String imageName)
Create an PsImage using the image at relative path specified by the string.
Parameters:
imageName - name of image file including a relative path.

PsImage

public PsImage(java.awt.Image anImage,
               java.lang.String alternateText)
Create an PsImage using the image specified. The other constructors eventually call this one, but you may want to call it directly if you already have an image (e.g. created via createImage).
Parameters:
image - The image
alternateText - Alternate text used if image cannot be retrieved
comp - Component necessay for media tracker
Method Detail

init

public void init()
Create MediaTracker.

setParentComponent

public void setParentComponent(java.awt.Component comp)
Set component used for MediaTracker in init() method

loadImage

public boolean loadImage()
Makes sure that the Image is loaded before returning from this method. Caller of this method may spin off a separate thread to do the loading. On the other hand, postponing the waiting as long as possible is more efficient, since loading can go on in the background.

getWidth

public int getWidth()
Get width of loaded image.

getHeight

public int getHeight()
Get height of loaded image.

getImage

public java.awt.Image getImage()
Get the image after loading it if not done yet.

setSize

public void setSize(int width,
                    int height)
Resizes the image after loading it if not done yet.

getPixels

public static int[] getPixels(java.awt.Image image,
                              int x,
                              int y,
                              int width,
                              int height,
                              int[] pixels,
                              int off,
                              int scan)
Parameters:
img - the image to retrieve pixels from
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
y - the y coordinate of the upper left corner of the rectangle of pixels to retrieve from the image
w - the width of the rectangle of pixels to retrieve
h - the height of the rectangle of pixels to retrieve
pix - the array of integers which are to be used to hold the RGB pixels retrieved from the image
off - the offset into the array of where to store the first pixel
scansize - the distance from one row of pixels to the next in the array

getPixels

public static int[] getPixels(java.awt.Image image)
Convert an image to an array of pixels.
Parameters:
img - the image to retrieve pixels from
Returns:
array of pixels on success, null on failure.

getImageFromArchive

public static PsImage getImageFromArchive(java.lang.String imageName,
                                          java.lang.String jarArchive)
Get an image from a jar archive.

Note, the cab-archive built with the automatic tool of VisualJ++ does not have the -p switch enabled which keeps relative path names. Therefore, I call the cabarc tool in the Custom section of this project. Then everything works fine with MS.

Netscape somehow neither reads the image nor the audio from its jar files. I expect that I did something wrong .... At least I kept the current state in which I have added the images and audio to the jar file which requires all to lie in the class/release tree.

Parameters:
imageName - name of image relative to root directory within the archive.
jarArchive - name of jar archive including relative path.

getImage

public static java.awt.Image getImage(java.lang.String imageName)
Get image relative to codeBase of applet, or from file system.
Parameters:
imageName - name of image file with relative url or absolute path.

getImage

public static java.awt.Image getImage(java.net.URL url)
Get image from absolute URL.

loadImage

public static boolean loadImage(java.awt.Component comp,
                                java.awt.Image image)
Load image with a media tracker and return when image is loaded or failure occurred.
Parameters:
comp - the component on which the images will eventually be drawn.
image - the image to be loaded and tracked by the media tracker.
Returns:
true on success.

createImageFromPixels

public static java.awt.Image createImageFromPixels(java.awt.Component comp,
                                                   int[] pixels,
                                                   int width,
                                                   int height,
                                                   int offset,
                                                   int scan)
Load image with a media tracker and return when image is loaded or failure occurred.
Parameters:
comp - the component on which the images will eventually be drawn.
pixels - array of pixels of the image.
width - width of the image
height - height of the image
offset - starting pixel in pixel array
scan - length of a scan line in pixel array
Returns:
image on success, else return null

JavaView® v2.12

The software JavaView® is copyright protected. All Rights Reserved.