Horus Doc || Java GUI Reference || Doxygen's quick Index  

CanvasJavaImage Class Reference

Extension of CanvasImage to display a "Java" Image on a Canvas. More...

Inheritance diagram for CanvasJavaImage::

CanvasImage CanvasObject List of all members.

Public Methods

 CanvasJavaImage ()
 Construct an empty image. More...

 CanvasJavaImage (int width, int height)
 Construct an empty image. More...

 CanvasJavaImage (Image im)
 Construct from a Java Image. More...

 CanvasJavaImage (BufferedImage im)
 Construct from a buffered Java Image. More...

 CanvasJavaImage (int[] pixels, double w, double h)
 Construct from a set of RGB pixels. More...

 CanvasJavaImage (String filename, Component comp)
 Construct from a file. More...

void draw (Graphics g)
 Draw CanvasObject on 'g', using internal CCS values. More...

Color getPixel (int x, int y)
void setPixel (int x, int y, Color c)
int[] getPixels (int x, int y, int w, int h)
BufferedImage getSubImage (int x, int y, int w, int h)
String[] getPixelStrings (int x, int y, int w, int h)
void moveImage (double x, double y)
 Moves the image to the (x,y) position, keeping current properties. More...


Protected Methods

void initImage (Image im)
void initImage (int width, int height)
void initImage (int[] pixels, int width, int height)

Detailed Description

Extension of CanvasImage to display a "Java" Image on a Canvas.

The sizes of the java image determine the sizes (in ICS) of the CanvasHxImage. The draw method of this class actually draws _bufIm at the CCS coordinates. So, Graphics.drawImage does the actual zooming of the pixel data.


Constructor & Destructor Documentation

CanvasJavaImage::CanvasJavaImage   [inline]
 

Construct an empty image.

00040 {
00041     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, 0., 0.);
00042 }

CanvasJavaImage::CanvasJavaImage int    width,
int    height
[inline]
 

Construct an empty image.

00048 {
00049     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, width, height);
00050     initImage(width, height);
00051 }

CanvasJavaImage::CanvasJavaImage Image    im [inline]
 

Construct from a Java Image.

00057 {
00058     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN,
00059           (double) im.getWidth(null), (double) im.getHeight(null));
00060     initImage(im);
00061 }

CanvasJavaImage::CanvasJavaImage BufferedImage    im [inline]
 

Construct from a buffered Java Image.

00067 {
00068     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN,
00069           (double) im.getWidth(null), (double) im.getHeight(null));
00070     initImage(im);
00071 }

CanvasJavaImage::CanvasJavaImage int    pixels[],
double    w,
double    h
[inline]
 

Construct from a set of RGB pixels.

00077 {
00078     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, w, h);
00079     initImage(pixels, (int) w, (int) h);
00080 }

CanvasJavaImage::CanvasJavaImage String    filename,
Component    comp
[inline]
 

Construct from a file.

comp is used to get at the ToolKit.

00086 {
00087     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, 0., 0.);
00088 
00089     File imFile = new File(filename);
00090     if (!(imFile.exists() && imFile.canRead()))
00091         return;
00092 
00093     Image im = comp.getToolkit().getImage(filename);
00094     MediaTracker t = new MediaTracker(comp);
00095     t.addImage(im, 0);
00096     try {
00097         t.waitForAll();
00098     } catch (InterruptedException e) {
00099         return;
00100     }
00101     if (im == null)
00102         return;
00103 
00104     setImageDim(im.getWidth(null), im.getHeight(null));
00105     initImage(im);
00106 }


Member Function Documentation

void CanvasJavaImage::draw Graphics    g [inline, virtual]
 

Draw CanvasObject on 'g', using internal CCS values.

Reimplemented from CanvasObject.

00110 {
00111     setupDrawMode(g);
00112     if (!getTransformOK()) {
00113         transformICStoCCS();
00114     }
00115 if (DEBUG_OBJECTS) {
00116 OutputStreamArea.println("Draw JavaImage called, image w: " + _bufIm.getWidth(null) +
00117                                                     ", h: " + _bufIm.getHeight(null));
00118 dump();
00119 }
00120     if (_bufIm != null)
00121         g.drawImage(_bufIm, getX1Ccs(), getY1Ccs(), getWidthCcs(), getHeightCcs(), null);
00122     else
00123         g.drawImage(_im, getX1Ccs(), getY1Ccs(), getWidthCcs(), getHeightCcs(), null);
00124 }

Color CanvasJavaImage::getPixel int    x,
int    y
[inline]
 

00138 {
00139     return (new Color(_bufIm.getRGB(x, y)));
00140 }

void CanvasJavaImage::setPixel int    x,
int    y,
Color    c
[inline, virtual]
 

Reimplemented from CanvasImage.

00144 {
00145     _bufIm.setRGB(x, y, c.getRGB());
00146 }

int [] CanvasJavaImage::getPixels int    x,
int    y,
int    w,
int    h
[inline]
 

00150 {
00151     return _bufIm.getRGB(x, y, w, h, null, 0, w);
00152 }

BufferedImage CanvasJavaImage::getSubImage int    x,
int    y,
int    w,
int    h
[inline, virtual]
 

Reimplemented from CanvasImage.

00156 {
00157     return _bufIm.getSubimage(x, y, w, h);
00158 }

String [] CanvasJavaImage::getPixelStrings int    x,
int    y,
int    w,
int    h
[inline, virtual]
 

Reimplemented from CanvasImage.

00162 {
00163     String[] strs = new String[w*h];
00164     int imWidth = _bufIm.getWidth();
00165     int imHeight = _bufIm.getHeight();
00166     for (int i=0; i<w; i++) {
00167         for (int j=0; j<h; j++) {
00168             if (x+i < 0 || y+j < 0 || x+i >= imWidth || y+j >= imHeight) {
00169                 strs[i+j*w] = new String("");
00170             } else {
00171                 int pix = _bufIm.getRGB(x+i, y+j);
00172                 Color c = new Color(pix);
00173                 strs[i+j*w] = HX.colorToString(c);
00174             }
00175         }
00176     }
00177     return strs;
00178 }

void CanvasJavaImage::moveImage double    x,
double    y
[inline]
 

Moves the image to the (x,y) position, keeping current properties.

Reimplemented from CanvasImage.

00183 {
00184     setImageDim(x, y, getWidth(), getHeight(), getZoomFactor());
00185 }

void CanvasJavaImage::initImage Image    im [inline, protected]
 

00195 {
00196     if (im instanceof BufferedImage) {
00197         _bufIm = (BufferedImage) im;
00198         return;
00199     }
00200 _bufIm = null;
00201 _im = im;
00202 /*
00203     int w = im.getWidth(null);
00204     int h = im.getHeight(null);
00205     int[] pixels = new int[w*h];
00206     PixelGrabber pg =
00207         new PixelGrabber(im, 0, 0, w, h, pixels, 0, w);
00208     try {
00209         pg.grabPixels();
00210     } catch (InterruptedException e) {
00211         return;
00212     }
00213     if ((pg.getStatus() & ImageObserver.ABORT) != 0)
00214         return;
00215 
00216     _bufIm = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
00217     _bufIm.setRGB(0, 0, w, h, pixels, 0, w);
00218 */
00219 }

void CanvasJavaImage::initImage int    width,
int    height
[inline, protected]
 

00223 {
00224     _bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00225 }

void CanvasJavaImage::initImage int    pixels[],
int    width,
int    height
[inline, protected]
 

00229 {
00230     _bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00231     _bufIm.setRGB(0, 0, width, height, pixels, 0, width);
00232 }


The documentation for this class was generated from the following file:
Generated on Tue Feb 3 14:19:39 2004 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001