API java : PixelGrabber


java.awt.image
Class PixelGrabber

java.lang.Object
  extended by java.awt.image.PixelGrabber
All Implemented Interfaces:
ImageConsumer

public class PixelGrabber
extends Object
implements ImageConsumer

The PixelGrabber class implements an ImageConsumer which can be attached to an Image or ImageProducer object to retrieve a subset of the pixels in that image. Here is an example:

  1. public void handlesinglepixel(int x, int y, int pixel) {
  2. int alpha = (pixel >> 24) & 0xff;
  3. int red = (pixel >> 16) & 0xff;
  4. int green = (pixel >> 8) & 0xff;
  5. int blue = (pixel ) & 0xff;
  6. // Deal with the pixel as necessary...
  7. }
  8.  
  9. public void handlepixels(Image img, int x, int y, int w, int h) {
  10. int[] pixels = new int[w * h];
  11. PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
  12. try {
  13. pg.grabPixels();
  14. } catch (InterruptedException e) {
  15. System.err.println("interrupted waiting for pixels!");
  16. return;
  17. }
  18. if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
  19. System.err.println("image fetch aborted or errored");
  20. return;
  21. }
  22. for (int j = 0; j < h; j++) {
  23. for (int i = 0; i < w; i++) {
  24. handlesinglepixel(x+i, y+j, pixels[j * w + i]);
  25. }
  26. }
  27. }

See Also:
ColorModel.getRGBdefault()

Field Summary
 
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
 
Constructor Summary
PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)
          Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image.
PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)
          Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image into the given array.
PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)
          Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the image produced by the specified ImageProducer into the given array.
 
Method Summary
 void abortGrabbing()
          Request the PixelGrabber to abort the image fetch.
 ColorModel getColorModel()
          Get the ColorModel for the pixels stored in the array.
 int getHeight()
          Get the height of the pixel buffer (after adjusting for image height).
 Object getPixels()
          Get the pixel buffer.
 int getStatus()
          Return the status of the pixels.
 int getWidth()
          Get the width of the pixel buffer (after adjusting for image width).
 boolean grabPixels()
          Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.
 boolean grabPixels(long ms)
          Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered or until the specified timeout has elapsed.
 void imageComplete(int status)
          The imageComplete method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setColorModel(ColorModel model)
          The setColorModel method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setDimensions(int width, int height)
          The setDimensions method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setHints(int hints)
          The setHints method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, byte[] pixels, int srcOff, int srcScan)
          The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, int[] pixels, int srcOff, int srcScan)
          The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void setProperties(Hashtable<?,?> props)
          The setProperties method is part of the ImageConsumer API which this class must implement to retrieve the pixels.
 void startGrabbing()
          Request the PixelGrabber to start fetching the pixels.
 int status()
          Returns the status of the pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PixelGrabber

public PixelGrabber(Image img,
                    int x,
                    int y,
                    int w,
                    int h,
                    int[] pix,
                    int off,
                    int scansize)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image into the given array. The pixels are stored into the array in the default RGB ColorModel. The RGB data for pixel (i, j) where (i, j) is inside the rectangle (x, y, w, h) is stored in the array at pix[(j - y) * scansize + (i - x) + off].

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
See Also:
ColorModel.getRGBdefault()

PixelGrabber

public PixelGrabber(ImageProducer ip,
                    int x,
                    int y,
                    int w,
                    int h,
                    int[] pix,
                    int off,
                    int scansize)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the image produced by the specified ImageProducer into the given array. The pixels are stored into the array in the default RGB ColorModel. The RGB data for pixel (i, j) where (i, j) is inside the rectangle (x, y, w, h) is stored in the array at pix[(j - y) * scansize + (i - x) + off].

Parameters:
ip - the ImageProducer that produces the image from which to retrieve pixels
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
See Also:
ColorModel.getRGBdefault()

PixelGrabber

public PixelGrabber(Image img,
                    int x,
                    int y,
                    int w,
                    int h,
                    boolean forceRGB)
Create a PixelGrabber object to grab the (x, y, w, h) rectangular section of pixels from the specified image. The pixels are accumulated in the original ColorModel if the same ColorModel is used for every call to setPixels, otherwise the pixels are accumulated in the default RGB ColorModel. If the forceRGB parameter is true, then the pixels will be accumulated in the default RGB ColorModel anyway. A buffer is allocated by the PixelGrabber to hold the pixels in either case. If (w < 0) or (h < 0), then they will default to the remaining width and height of the source data when that information is delivered.

Parameters:
img - the image to retrieve the image data 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
forceRGB - true if the pixels should always be converted to the default RGB ColorModel
Method Detail

startGrabbing

public void startGrabbing()
Request the PixelGrabber to start fetching the pixels.


abortGrabbing

public void abortGrabbing()
Request the PixelGrabber to abort the image fetch.


grabPixels

public boolean grabPixels()
                   throws InterruptedException
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.

Returns:
true if the pixels were successfully grabbed, false on abort, error or timeout
Throws:
InterruptedException - Another thread has interrupted this thread.

grabPixels

public boolean grabPixels(long ms)
                   throws InterruptedException
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered or until the specified timeout has elapsed. This method behaves in the following ways, depending on the value of ms:
  • If ms == 0, waits until all pixels are delivered
  • If ms > 0, waits until all pixels are delivered as timeout expires.
  • If ms < 0, returns true if all pixels are grabbed, false otherwise and does not wait.

Parameters:
ms - the number of milliseconds to wait for the image pixels to arrive before timing out
Returns:
true if the pixels were successfully grabbed, false on abort, error or timeout
Throws:
InterruptedException - Another thread has interrupted this thread.

getStatus

public int getStatus()
Return the status of the pixels. The ImageObserver flags representing the available pixel information are returned.

Returns:
the bitwise OR of all relevant ImageObserver flags
See Also:
ImageObserver

getWidth

public int getWidth()
Get the width of the pixel buffer (after adjusting for image width). If no width was specified for the rectangle of pixels to grab then then this information will only be available after the image has delivered the dimensions.

Returns:
the final width used for the pixel buffer or -1 if the width is not yet known
See Also:
getStatus()

getHeight

public int getHeight()
Get the height of the pixel buffer (after adjusting for image height). If no width was specified for the rectangle of pixels to grab then then this information will only be available after the image has delivered the dimensions.

Returns:
the final height used for the pixel buffer or -1 if the height is not yet known
See Also:
getStatus()

getPixels

public Object getPixels()
Get the pixel buffer. If the PixelGrabber was not constructed with an explicit pixel buffer to hold the pixels then this method will return null until the size and format of the image data is known. Since the PixelGrabber may fall back on accumulating the data in the default RGB ColorModel at any time if the source image uses more than one ColorModel to deliver the data, the array object returned by this method may change over time until the image grab is complete.

Returns:
either a byte array or an int array
See Also:
getStatus(), setPixels(int, int, int, int, ColorModel, byte[], int, int), setPixels(int, int, int, int, ColorModel, int[], int, int)

getColorModel

public ColorModel getColorModel()
Get the ColorModel for the pixels stored in the array. If the PixelGrabber was constructed with an explicit pixel buffer then this method will always return the default RGB ColorModel, otherwise it may return null until the ColorModel used by the ImageProducer is known. Since the PixelGrabber may fall back on accumulating the data in the default RGB ColorModel at any time if the source image uses more than one ColorModel to deliver the data, the ColorModel object returned by this method may change over time until the image grab is complete and may not reflect any of the ColorModel objects that was used by the ImageProducer to deliver the pixels.

Returns:
the ColorModel object used for storing the pixels
See Also:
getStatus(), ColorModel.getRGBdefault(), setColorModel(ColorModel)

setDimensions

public void setDimensions(int width,
                          int height)
The setDimensions method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setDimensions in interface ImageConsumer
Parameters:
width - the width of the dimension
height - the height of the dimension

setHints

public void setHints(int hints)
The setHints method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setHints in interface ImageConsumer
Parameters:
hints - a set of hints used to process the pixels

setProperties

public void setProperties(Hashtable<?,?> props)
The setProperties method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setProperties in interface ImageConsumer
Parameters:
props - the list of properties

setColorModel

public void setColorModel(ColorModel model)
The setColorModel method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setColorModel in interface ImageConsumer
Parameters:
model - the specified ColorModel
See Also:
getColorModel()

setPixels

public void setPixels(int srcX,
                      int srcY,
                      int srcW,
                      int srcH,
                      ColorModel model,
                      byte[] pixels,
                      int srcOff,
                      int srcScan)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setPixels in interface ImageConsumer
Parameters:
srcX, srcY - the coordinates of the upper-left corner of the area of pixels to be set
srcW - the width of the area of pixels
srcH - the height of the area of pixels
model - the specified ColorModel
pixels - the array of pixels
srcOff - the offset into the pixels array
srcScan - the distance from one row of pixels to the next in the pixels array
See Also:
getPixels()

setPixels

public void setPixels(int srcX,
                      int srcY,
                      int srcW,
                      int srcH,
                      ColorModel model,
                      int[] pixels,
                      int srcOff,
                      int srcScan)
The setPixels method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
setPixels in interface ImageConsumer
Parameters:
srcX, srcY - the coordinates of the upper-left corner of the area of pixels to be set
srcW - the width of the area of pixels
srcH - the height of the area of pixels
model - the specified ColorModel
pixels - the array of pixels
srcOff - the offset into the pixels array
srcScan - the distance from one row of pixels to the next in the pixels array
See Also:
getPixels()

imageComplete

public void imageComplete(int status)
The imageComplete method is part of the ImageConsumer API which this class must implement to retrieve the pixels.

Note: This method is intended to be called by the ImageProducer of the Image whose pixels are being grabbed. Developers using this class to retrieve pixels from an image should avoid calling this method directly since that operation could result in problems with retrieving the requested pixels.

Specified by:
imageComplete in interface ImageConsumer
Parameters:
status - the status of image loading
See Also:
ImageProducer.removeConsumer(java.awt.image.ImageConsumer)

status

public int status()
Returns the status of the pixels. The ImageObserver flags representing the available pixel information are returned. This method and getStatus have the same implementation, but getStatus is the preferred method because it conforms to the convention of naming information-retrieval methods with the form "getXXX".

Returns:
the bitwise OR of all relevant ImageObserver flags
See Also:
ImageObserver, getStatus()

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

7 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-3556
Document créé le 15/09/06 22:47, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-java/awt/image/PixelGrabber.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,64 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
La télé : c'est la vision carrée d'un monde qui ne tourne pas rond.

Franck Dhumes [Extrait de Annulaire des mots]
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 14:55, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)