Java Doc for PixelGrabber.java in  » 6.0-JDK-Core » AWT » java » awt » image » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt.image 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.image.PixelGrabber

PixelGrabber
public class PixelGrabber implements ImageConsumer(Code)
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:
 public void handlesinglepixel(int x, int y, int pixel) {
 int alpha = (pixel >> 24) & 0xff;
 int red   = (pixel >> 16) & 0xff;
 int green = (pixel >>  8) & 0xff;
 int blue  = (pixel      ) & 0xff;
 // Deal with the pixel as necessary...
 }
 public void handlepixels(Image img, int x, int y, int w, int h) {
 int[] pixels = new int[w * h];
 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
 try {
 pg.grabPixels();
 } catch (InterruptedException e) {
 System.err.println("interrupted waiting for pixels!");
 return;
 }
 if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
 System.err.println("image fetch aborted or errored");
 return;
 }
 for (int j = 0; j < h; j++) {
 for (int i = 0; i < w; i++) {
 handlesinglepixel(x+i, y+j, pixels[j * w + i]);
 }
 }
 }
 

See Also:   ColorModel.getRGBdefault
version:
   1.33, 05/05/07
author:
   Jim Graham


Field Summary
 byte[]bytePixels
    
 intdstH
    
 intdstOff
    
 intdstScan
    
 intdstW
    
 intdstX
    
 intdstY
    
 ColorModelimageModel
    
 int[]intPixels
    
 ImageProducerproducer
    

Constructor Summary
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.
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.
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.

Method Summary
public synchronized  voidabortGrabbing()
     Request the PixelGrabber to abort the image fetch.
public synchronized  ColorModelgetColorModel()
     Get the ColorModel for the pixels stored in the array.
public synchronized  intgetHeight()
     Get the height of the pixel buffer (after adjusting for image height).
public synchronized  ObjectgetPixels()
     Get the pixel buffer.
public synchronized  intgetStatus()
     Return the status of the pixels.
public synchronized  intgetWidth()
     Get the width of the pixel buffer (after adjusting for image width).
public  booleangrabPixels()
     Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered.
public synchronized  booleangrabPixels(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.
public synchronized  voidimageComplete(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.

public  voidsetColorModel(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.

public  voidsetDimensions(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.

public  voidsetHints(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.

public  voidsetPixels(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.

public  voidsetPixels(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.

public  voidsetProperties(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.

public synchronized  voidstartGrabbing()
     Request the PixelGrabber to start fetching the pixels.
public synchronized  intstatus()
     Returns the status of the pixels.

Field Detail
bytePixels
byte[] bytePixels(Code)



dstH
int dstH(Code)



dstOff
int dstOff(Code)



dstScan
int dstScan(Code)



dstW
int dstW(Code)



dstX
int dstX(Code)



dstY
int dstY(Code)



imageModel
ColorModel imageModel(Code)



intPixels
int[] intPixels(Code)



producer
ImageProducer producer(Code)




Constructor Detail
PixelGrabber
public PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)(Code)
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].
See Also:   ColorModel.getRGBdefault
Parameters:
  img - the image to retrieve pixels from
Parameters:
  x - the x coordinate of the upper left corner of the rectangleof pixels to retrieve from the image, relative to the default(unscaled) size of the image
Parameters:
  y - the y coordinate of the upper left corner of the rectangleof pixels to retrieve from the image
Parameters:
  w - the width of the rectangle of pixels to retrieve
Parameters:
  h - the height of the rectangle of pixels to retrieve
Parameters:
  pix - the array of integers which are to be used to hold theRGB pixels retrieved from the image
Parameters:
  off - the offset into the array of where to store the first pixel
Parameters:
  scansize - the distance from one row of pixels to the next inthe array



PixelGrabber
public PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)(Code)
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
Parameters:
  x - the x coordinate of the upper left corner of the rectangleof pixels to retrieve from the image, relative to the default(unscaled) size of the image
Parameters:
  y - the y coordinate of the upper left corner of the rectangleof pixels to retrieve from the image
Parameters:
  w - the width of the rectangle of pixels to retrieve
Parameters:
  h - the height of the rectangle of pixels to retrieve
Parameters:
  pix - the array of integers which are to be used to hold theRGB pixels retrieved from the image
Parameters:
  off - the offset into the array of where to store the first pixel
Parameters:
  scansize - the distance from one row of pixels to the next inthe array
See Also:   ColorModel.getRGBdefault



PixelGrabber
public PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)(Code)
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
Parameters:
  x - the x coordinate of the upper left corner of the rectangleof pixels to retrieve from the image, relative to the default(unscaled) size of the image
Parameters:
  y - the y coordinate of the upper left corner of the rectangleof pixels to retrieve from the image
Parameters:
  w - the width of the rectangle of pixels to retrieve
Parameters:
  h - the height of the rectangle of pixels to retrieve
Parameters:
  forceRGB - true if the pixels should always be converted tothe default RGB ColorModel




Method Detail
abortGrabbing
public synchronized void abortGrabbing()(Code)
Request the PixelGrabber to abort the image fetch.



getColorModel
public synchronized ColorModel getColorModel()(Code)
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. the ColorModel object used for storing the pixels
See Also:   PixelGrabber.getStatus
See Also:   ColorModel.getRGBdefault
See Also:   PixelGrabber.setColorModel(ColorModel)



getHeight
public synchronized int getHeight()(Code)
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. the final height used for the pixel buffer or -1 if the heightis not yet known
See Also:   PixelGrabber.getStatus



getPixels
public synchronized Object getPixels()(Code)
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. either a byte array or an int array
See Also:   PixelGrabber.getStatus
See Also:   PixelGrabber.setPixels(int,int,int,int,ColorModel,byte[],int,int)
See Also:   PixelGrabber.setPixels(int,int,int,int,ColorModel,int[],int,int)



getStatus
public synchronized int getStatus()(Code)
Return the status of the pixels. The ImageObserver flags representing the available pixel information are returned. the bitwise OR of all relevant ImageObserver flags
See Also:   ImageObserver



getWidth
public synchronized int getWidth()(Code)
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. the final width used for the pixel buffer or -1 if the widthis not yet known
See Also:   PixelGrabber.getStatus



grabPixels
public boolean grabPixels() throws InterruptedException(Code)
Request the Image or ImageProducer to start delivering pixels and wait for all of the pixels in the rectangle of interest to be delivered. true if the pixels were successfully grabbed, false onabort, error or timeout
exception:
  InterruptedException - Another thread has interrupted this thread.



grabPixels
public synchronized boolean grabPixels(long ms) throws InterruptedException(Code)
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 pixelsto arrive before timing out true if the pixels were successfully grabbed, false onabort, error or timeout
exception:
  InterruptedException - Another thread has interrupted this thread.



imageComplete
public synchronized void imageComplete(int status)(Code)
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.
Parameters:
  status - the status of image loading




setColorModel
public void setColorModel(ColorModel model)(Code)
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.
Parameters:
  model - the specified ColorModel
See Also:   PixelGrabber.getColorModel




setDimensions
public void setDimensions(int width, int height)(Code)
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.
Parameters:
  width - the width of the dimension
Parameters:
  height - the height of the dimension




setHints
public void setHints(int hints)(Code)
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.
Parameters:
  hints - a set of hints used to process the pixels




setPixels
public void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, byte pixels, int srcOff, int srcScan)(Code)
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.
Parameters:
  srcX - the X coordinate of the upper-left cornerof the area of pixels to be set
Parameters:
  srcY - the Y coordinate of the upper-left cornerof the area of pixels to be set
Parameters:
  srcW - the width of the area of pixels
Parameters:
  srcH - the height of the area of pixels
Parameters:
  model - the specified ColorModel
Parameters:
  pixels - the array of pixels
Parameters:
  srcOff - the offset into the pixels array
Parameters:
  srcScan - the distance from one row of pixels to the nextin the pixels array
See Also:   PixelGrabber.getPixels




setPixels
public void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, int pixels, int srcOff, int srcScan)(Code)
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.
Parameters:
  srcX - the X coordinate of the upper-left cornerof the area of pixels to be set
Parameters:
  srcY - the Y coordinate of the upper-left cornerof the area of pixels to be set
Parameters:
  srcW - the width of the area of pixels
Parameters:
  srcH - the height of the area of pixels
Parameters:
  model - the specified ColorModel
Parameters:
  pixels - the array of pixels
Parameters:
  srcOff - the offset into the pixels array
Parameters:
  srcScan - the distance from one row of pixels to the nextin the pixels array
See Also:   PixelGrabber.getPixels




setProperties
public void setProperties(Hashtable props)(Code)
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.
Parameters:
  props - the list of properties




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



status
public synchronized int status()(Code)
Returns the status of the pixels. The ImageObserver flags representing the available pixel information are returned. This method and PixelGrabber.getStatus() 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". the bitwise OR of all relevant ImageObserver flags
See Also:   ImageObserver
See Also:   PixelGrabber.getStatus()



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.