Documentation of 'jv.objectGui.PsImage' Java class
PsImage ("JavaView Reference Manual")
"JavaView? v5.03.003"
jv.objectGui

Class PsImage



  • public class PsImage
    extends java.lang.Object
    A 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.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 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.
      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.
      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 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 image
        alternateText - 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 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)
        Convert a subrectangle of an image to an array of pixels.
        Parameters:
        image - 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
        width - the width of the rectangle of pixels to retrieve
        height - the height of the rectangle of pixels to retrieve
        pixels - 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
        scan - 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, null on 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:
        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
      • 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)
"JavaView? v5.03.003"

"

The software JavaView? is copyright protected. All Rights Reserved.
"

Ads help maintain this website.