Methods for Extracting and Setting Samples in a DataBuffer
There are two categories of methods that can be used for extracting samples from a data buffer. The first category contains the getSampleXXX methods. To extract the samples from a data buffer as integer values, use the following methods:
- public int getSample(int x, int y, int band, DataBuffer DB): This method returns an int representing the sample from the specified band belonging to a pixel with the (x,y) coordinates. You also specify the data buffer:
int sample=SM.getSample(20,35,2,DB);
System.out.println("Sample value:"+sample);
- public int[] getSamples(int x,int y, int w, int h, int band, int[] res, DataBuffer DB): This method returns an array of integers representing all the samples in the rectangular area (x,y,w,h). Select the band and the data buffer by supplying the arguments band and DB. The samples are stored in the res array, one sample per element:
int[] res=new int[W*H];
res=SM.getSamples(0,0,W,H,0,res,DF);
for(int i=0;i<res.length;i++)
System.out.println("res["+i+"]="+res[i]);
If you want to extract the samples from a data buffer as float values, use these two methods:
- public float getSampleFloat(int x, int y, int band, DataBuffer DB)
- public float[] getSamples(int x,int y, int w, int h, int band, float[] res, DataBuffer DB)
If you want to extract the samples from a data buffer as double values, use these two methods:
- public double getSampleDouble(int x, int y, int band, DataBuffer DB)
- public double[] getSamples(int x,int y, int w, int h, int band, double[] res, DataBuffer DB)
To understand the above four methods, try making an analogy with the methods from this category used to extract the samples from a data buffer as integer values.
The second category contains the getPixelXXX methods. To extract the samples from a data buffer as integer values, use the following methods:
- public int[] getPixel(int x, int y, int[] res, DataBuffer DB): This method returns all the samples of the pixel that have the (x,y) coordinates in the integer res array. The DB argument represents the data buffer.
int[] res=new int[SM.getNumBands()];
res=SM.getPixel(45,35,res,DF);
for(int i=0;i<res.length;i++)
System.out.println("res["+i+"]="+res[i]);
- public int[] getPixels(int x, int y, int l, int h, int[] res, DataBuffer DB): This method returns an array of integers representing all the samples of the pixels found in the rectangular area (x,y,w,h). Every res element stores one sample. The DB argument represents the data buffer.
int[] res=new int[W*H*SM.getNumBands()];
res=SM.getPixels(0,0,W,H,res,DF);
for(int i=0;i<res.length;i++)
System.out.println("res["+i+"]="+res[i]);
To return the samples in a float array, use the following two methods:
- public float[] getPixel(int x, int y, float[] res, DataBuffer DB)
- public float[] getPixels(int x, int y, int w, int h, float[] res, DataBuffer DB)
To return the samples in a float array, use the following two methods:
- public double[] getPixel(int x, int y, double[] res, DataBuffer DB)
- public double[] getPixels(int x, int y, int w, int h, double[] res, DataBuffer DB)
To understand the above four methods, try making an analogy with the methods from this category used to extract the samples from a data buffer as integer values.
To set the samples in a DataBuffer, use the group of set methods. These methods are similar to the get methods for extracting samples from a DataBuffer.
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|