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)

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.

00036 {
00037     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, 0., 0.);
00038 }

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

Construct an empty image.

00044 {
00045     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, width, height);
00046     initImage(width, height);
00047 }

CanvasJavaImage::CanvasJavaImage Image    im [inline]
 

Construct from a Java Image.

00053 {
00054     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN,
00055           (double) im.getWidth(null), (double) im.getHeight(null));
00056     initImage(im);
00057 }

CanvasJavaImage::CanvasJavaImage BufferedImage    im [inline]
 

Construct from a buffered Java Image.

00063 {
00064     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN,
00065           (double) im.getWidth(null), (double) im.getHeight(null));
00066     initImage(im);
00067 }

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

Construct from a set of RGB pixels.

00073 {
00074     super(Converter.ICS_ORIGIN, Converter.ICS_ORIGIN, w, h);
00075     initImage(pixels, (int) w, (int) h);
00076 }

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

Construct from a file.

comp is used to get at the ToolKit.

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


Member Function Documentation

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

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

Reimplemented from CanvasObject.

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

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

00134 {
00135     return (new Color(_bufIm.getRGB(x, y)));
00136 }

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

Reimplemented from CanvasImage.

00140 {
00141     _bufIm.setRGB(x, y, c.getRGB());
00142 }

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

00146 {
00147     return _bufIm.getRGB(x, y, w, h, null, 0, w);
00148 }

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

Reimplemented from CanvasImage.

00152 {
00153     return _bufIm.getSubimage(x, y, w, h);
00154 }

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

Reimplemented from CanvasImage.

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

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

00185 {
00186     if (im instanceof BufferedImage) {
00187         _bufIm = (BufferedImage) im;
00188         return;
00189     }
00190 _bufIm = null;
00191 _im = im;
00192 /*
00193     int w = im.getWidth(null);
00194     int h = im.getHeight(null);
00195     int[] pixels = new int[w*h];
00196     PixelGrabber pg =
00197         new PixelGrabber(im, 0, 0, w, h, pixels, 0, w);
00198     try {
00199         pg.grabPixels();
00200     } catch (InterruptedException e) {
00201         return;
00202     }
00203     if ((pg.getStatus() & ImageObserver.ABORT) != 0)
00204         return;
00205 
00206     _bufIm = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
00207     _bufIm.setRGB(0, 0, w, h, pixels, 0, w);
00208 */
00209 }

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

00213 {
00214     _bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00215 }

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

00219 {
00220     _bufIm = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
00221     _bufIm.setRGB(0, 0, width, height, pixels, 0, width);
00222 }


The documentation for this class was generated from the following file:
Generated on Mon Jan 27 15:11:16 2003 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001