jv.objectGui
Class PsImage
- java.lang.Object
-
- jv.objectGui.PsImage
-
public class PsImage extends java.lang.ObjectA class for loading and handling images.- Author:
- Konrad Polthier
- Version:
- 26.01.02, 1.50 revised (kp) Moved the method getImageFromArchive to JarResource from PsImage.
18.01.00, 1.01 revised (kp) Changed superclass from PsObject to java.lang.Object.
02.01.99, 1.00 created (kp)
-
-
Constructor Summary
Constructors Constructor and Description PsImage(java.awt.Image image, 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static java.awt.ImagecreateImageFromPixels(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.intgetHeight()Get height of loaded image.java.awt.ImagegetImage()Get the image after loading it if not done yet.static java.awt.ImagegetImage(java.lang.String imageName)Get image relative to codeBase of applet, or from file system.static java.awt.ImagegetImage(java.net.URL url)Get image from absolute URL.static java.awt.ImagegetImageResource(java.lang.String s)Get a GIF or JPG (and now PNG too) image from a resource including the current jar archives.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)Convert a subrectangle of an image to an array of pixels.intgetWidth()Get width of loaded image.voidinit()Create MediaTracker.booleanloadImage()Makes sure that the Image is loaded before returning from this method.static booleanloadImage(java.awt.Component comp, java.awt.Image image)Load image with a media tracker and return when image is loaded or failure occurred.voidsetParentComponent(java.awt.Component comp)Set component used for MediaTracker ininit()methodvoidsetSize(int width, int height)Resizes the image after loading it if not done yet.
-
-
-
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 image, 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 imagealternateText- Alternate text used if image cannot be retrieved
-
-
Method Detail
-
init
public void init()
Create MediaTracker.
-
setParentComponent
public void setParentComponent(java.awt.Component comp)
Set component used for MediaTracker ininit()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)Convert a subrectangle of an image to an array of pixels.- Parameters:
image- the image to retrieve pixels fromx- 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 imagey- the y coordinate of the upper left corner of the rectangle of pixels to retrieve from the imagewidth- the width of the rectangle of pixels to retrieveheight- the height of the rectangle of pixels to retrievepixels- the array of integers which are to be used to hold the RGB pixels retrieved from the imageoff- the offset into the array of where to store the first pixelscan- 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:
image- the image to retrieve pixels from- Returns:
- array of pixels on success,
nullon failure.
-
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.- Version:
- 14.09.06, 1.25 (kp) Disabled waiting for isActive(), seems to be no necessity.
26.10.04, 1.20 (kp) Trying period iterates maximal 10 times, each with a 100ms sleep.
13.02.02, 1.15 (kp) Check if applet is active, i.e. its init() method has finished.
10.10.01, 1.10 (kp) Try without and with codebase in application mode.
00.00.00, 1.00 (kp) Code created inside a developer applet.
-
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:
trueon 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 imageheight- height of the imageoffset- starting pixel in pixel arrayscan- length of a scan line in pixel array- Returns:
- image on success, else return
null
-
getImageResource
public static java.awt.Image getImageResource(java.lang.String s)
Get a GIF or JPG (and now PNG too) image from a resource including the current jar archives. If image is not available as resource in a JAR file then give it another try and search below the current codebase in the file system.- Since:
- JavaView 2.66.002
- Version:
- 22.06.15, 2.60 revised (kp) Bug in loading correct.
02.03.14, 2.50 revised (kp) Catch exception when resource not found.
03.01.07, 2.10 revised (kp) Additional check if PsConfig.getApplet is available.
19.11.06, 2.00 revised (kp) Method moved to PsImage from javaview.
02.04.03, 1.00 created (kp)
-
-
"