|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.image.SampleModel
java.awt.image.SinglePixelPackedSampleModel
public class SinglePixelPackedSampleModel
此類別表示壓縮的像素資料:將 N 個樣本組成的單個像素存儲在單個資料陣列元素中,每個資料陣列元素只保存一個像素的樣本。此類別支持 TYPE_BYTE、TYPE_USHORT 和 TYPE_INT 資料型別。所有資料陣列元素都位於 DataBuffer 的第一個存儲單元中。該類別提供了一些存取方法,以便直接操作圖像資料。掃瞄行間距是給定樣本和下一個掃瞄行同一列中對應樣本之間的資料陣列元素數。位遮罩碼是提取表示像素 band 樣本所需的遮罩碼。位偏移量是樣本資料陣列元素中位的偏移量,其中樣本表示像素的 band。
以下程式碼說明了如何從 DataBuffer data 中提取表示像素 x,y 處 band b 的樣本位:
int sample = data.getElem(y * scanlineStride + x);
sample = (sample & bitMasks[b]) >>> bitOffsets[b];
| 欄位摘要 |
|---|
| 從類別 java.awt.image.SampleModel 繼承的欄位 |
|---|
dataType, height, numBands, width |
| 建構子摘要 | |
|---|---|
SinglePixelPackedSampleModel(int dataType,
int w,
int h,
int[] bitMasks)
建構一個具有 bitMasks.length band 的 SinglePixelPackedSampleModel。 |
|
SinglePixelPackedSampleModel(int dataType,
int w,
int h,
int scanlineStride,
int[] bitMasks)
建構一個 SinglePixelPackedSampleModel,使其具有 bitMasks.length band,且掃瞄行間距等於 scanlineStride 資料陣列元素。 |
|
| 方法摘要 | |
|---|---|
SampleModel |
createCompatibleSampleModel(int w,
int h)
創建一個具有指定寬度和高度的新 SinglePixelPackedSampleModel。 |
DataBuffer |
createDataBuffer()
創建一個對應於此 SinglePixelPackedSampleModel 的 DataBuffer。 |
SampleModel |
createSubsetSampleModel(int[] bands)
創建一個新 SinglePixelPackedSampleModel,使其具有此 SinglePixelPackedSampleModel 的 band 子集。 |
boolean |
equals(Object o)
指示其他某個物件是否與此物件「相等」。 |
int[] |
getBitMasks()
返回所有 band 的位遮罩碼。 |
int[] |
getBitOffsets()
返回表示所有 band 像素的資料陣列元素中的位偏移量。 |
Object |
getDataElements(int x,
int y,
Object obj,
DataBuffer data)
返回 TransferType 型別基本陣列中單個像素的資料。 |
int |
getNumDataElements()
返回通過 getDataElements 和 setDataElements 方法傳輸一個像素所需的資料元素數。 |
int |
getOffset(int x,
int y)
返回像素 (x,y)(在資料陣列元素中)的偏移量。 |
int[] |
getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
在一個 int 陣列中返回對應於指定像素的所有樣本。 |
int[] |
getPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
在一個 int 陣列中返回對應於指定像素矩形的所有樣本,每個陣列元素對應一個樣本。 |
int |
getSample(int x,
int y,
int b,
DataBuffer data)
以 int 形式返回指定 band 中對應於 (x,y) 處像素的樣本。 |
int[] |
getSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
在一個 int 陣列中返回指定 band 中對應於指定像素矩形的樣本,每個陣列元素對應一個樣本。 |
int[] |
getSampleSize()
返回所有 band 的每樣本位數。 |
int |
getSampleSize(int band)
返回指定 band 的每樣本位數。 |
int |
getScanlineStride()
返回此 SinglePixelPackedSampleModel 的掃瞄行間距。 |
int |
hashCode()
返回該物件的雜湊碼值。 |
void |
setDataElements(int x,
int y,
Object obj,
DataBuffer data)
根據 TransferType 型別的基本陣列設置指定 DataBuffer 中單個像素的資料。 |
void |
setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
使用輸入樣本的 int 陣列設置 DataBuffer 中的像素。 |
void |
setPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
根據 int 陣列設置像素矩形的所有樣本,該陣列為每個陣列元素包含一個樣本。 |
void |
setSample(int x,
int y,
int b,
int s,
DataBuffer data)
使用輸入的 int 設置指定 band 中對應於 DataBuffer (x,y) 處像素的樣本。 |
void |
setSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
根據 int 陣列設置指定 band 中對應於指定像素矩形的樣本,該陣列為每個陣列元素包含一個樣本。 |
| 從類別 java.awt.image.SampleModel 繼承的方法 |
|---|
getDataElements, getDataType, getHeight, getNumBands, getPixel, getPixel, getPixels, getPixels, getSampleDouble, getSampleFloat, getSamples, getSamples, getTransferType, getWidth, setDataElements, setPixel, setPixel, setPixels, setPixels, setSample, setSample, setSamples, setSamples |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| 建構子詳細資訊 |
|---|
public SinglePixelPackedSampleModel(int dataType,
int w,
int h,
int[] bitMasks)
dataType - 存儲樣本使用的資料型別。w - 所描述的圖像資料區域的寬度(以像素為單位)。h - 所描述的圖像資料區域的高度(以像素為單位)。bitMasks - 所有 band 的位遮罩碼。
IllegalArgumentException - 如果 dataType 不是 DataBuffer.TYPE_BYTE、DataBuffer.TYPE_USHORT 或 DataBuffer.TYPE_INT
public SinglePixelPackedSampleModel(int dataType,
int w,
int h,
int scanlineStride,
int[] bitMasks)
dataType - 存儲樣本使用的資料型別。w - 所描述的圖像資料區域的寬度(以像素為單位)。h - 所描述的圖像資料區域的高度(以像素為單位)。scanlineStride - 圖像資料的行間距。bitMasks - 所有 band 的位遮罩碼。
IllegalArgumentException - 如果 w 或 h 不大於 0
IllegalArgumentException - 如果 bitMask 中的任何遮罩碼不連續
IllegalArgumentException - 如果 dataType 不是 DataBuffer.TYPE_BYTE、DataBuffer.TYPE_USHORT 或 DataBuffer.TYPE_INT| 方法詳細資訊 |
|---|
public int getNumDataElements()
SampleModel 中的 getNumDataElementsSampleModel.getDataElements(int, int, Object, DataBuffer),
SampleModel.getDataElements(int, int, int, int, Object, DataBuffer),
SampleModel.setDataElements(int, int, Object, DataBuffer),
SampleModel.setDataElements(int, int, int, int, Object, DataBuffer),
SampleModel.getTransferType()
public SampleModel createCompatibleSampleModel(int w,
int h)
SampleModel 中的 createCompatibleSampleModelw - 得到的 SampleModel 的寬度h - 得到的 SampleModel 的高度
SinglePixelPackedSampleModel。
IllegalArgumentException - 如果 w 或 h 不大於 0public DataBuffer createDataBuffer()
SampleModel 中的 createDataBufferSampleModel 的 DataBuffer。public int[] getSampleSize()
SampleModel 中的 getSampleSizepublic int getSampleSize(int band)
SampleModel 中的 getSampleSizeband - 指定的 band
public int getOffset(int x,
int y)
x,y 的資料元素可以使用 SinglePixelPackedSampleModel sppsm 從 DataBuffer data 中檢索:
data.getElem(sppsm.getOffset(x, y));
x - 指定像素的 X 坐標y - 指定像素的 Y 坐標
public int[] getBitOffsets()
public int[] getBitMasks()
public int getScanlineStride()
SinglePixelPackedSampleModel 的掃瞄行間距。public SampleModel createSubsetSampleModel(int[] bands)
SampleModel 中的 createSubsetSampleModelbands - 此 SampleModel 的 band 子集
SampleModel band 子集的 SampleModel。
RasterFormatException - 如果 band 參數的長度大於樣本模型中 band 的數量。
public Object getDataElements(int x,
int y,
Object obj,
DataBuffer data)
以下程式碼說明了如何將一個像素的資料從 DataBuffer db1(其存儲佈局由 SinglePixelPackedSampleModel sppsm1 描述)傳輸到 DataBuffer db2(其存儲佈局由 SinglePixelPackedSampleModel sppsm2 描述)。該傳輸通常比使用 getPixel/setPixel 更有效。
SinglePixelPackedSampleModel sppsm1, sppsm2;
DataBufferInt db1, db2;
sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null,
db1), db2);
如果兩個 SampleModel 具有相同的 band 數量,相應 band 的每個樣本具有相同的位數,且 TransferType 相同,則使用 getDataElements/setDataElements 在兩個 DataBuffer/SampleModel 對之間進行傳輸是合法的。
如果 obj 不為 null,則它應是 TransferType 型別的基本陣列。否則拋出 ClassCastException。如果坐標不在範圍內,或者 obj 不為 null 且大小不足以保存像素資料,則拋出 ArrayIndexOutOfBoundsException。
SampleModel 中的 getDataElementsx - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。obj - 如果不為 null,則 obj 是接收返回像素資料的基本陣列。data - 套件含圖像資料的 DataBuffer。
setDataElements(int, int, Object, DataBuffer)
public int[] getPixel(int x,
int y,
int[] iArray,
DataBuffer data)
SampleModel 中的 getPixelx - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。iArray - 如果不為 null,則在此陣列中返回樣本data - 套件含圖像資料的 DataBuffer。
setPixel(int, int, int[], DataBuffer)
public int[] getPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
SampleModel 中的 getPixelsx - 左上角像素位置的 X 坐標。y - 左上角像素位置的 Y 坐標。w - 像素矩形的寬度。h - 像素矩形的高度。iArray - 如果不為 null,則在此陣列中返回樣本。data - 套件含圖像資料的 DataBuffer。
setPixels(int, int, int, int, int[], DataBuffer)
public int getSample(int x,
int y,
int b,
DataBuffer data)
SampleModel 中的 getSamplex - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。b - 要返回的 band。data - 套件含圖像資料的 DataBuffer。
setSample(int, int, int, int, DataBuffer)
public int[] getSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
SampleModel 中的 getSamplesx - 左上角像素位置的 X 坐標。y - 左上角像素位置的 Y 坐標。w - 像素矩形的寬度。h - 像素矩形的高度。b - 要返回的 band。iArray - 如果不為 null,則在此陣列中返回樣本。data - 套件含圖像資料的 DataBuffer。
setSamples(int, int, int, int, int, int[], DataBuffer)
public void setDataElements(int x,
int y,
Object obj,
DataBuffer data)
以下程式碼說明了如何將一個像素的資料從 DataBuffer db1(其存儲佈局由 SinglePixelPackedSampleModel sppsm1 描述)傳輸到 DataBuffer db2(其存儲佈局由 SinglePixelPackedSampleModel sppsm2 描述)。該傳輸通常比使用 getPixel/setPixel 更有效。
SinglePixelPackedSampleModel sppsm1, sppsm2;
DataBufferInt db1, db2;
sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null,
db1), db2);
如果兩個 SampleModel 具有相同的 band 數量,相應 band 的每個樣本具有相同的位數,且 TransferType 相同,則使用 getDataElements/setDataElements 在兩個 DataBuffer/SampleModel 對之間進行傳輸是合法的。
obj 必須是 TransferType 型別的基本陣列。否則拋出 ClassCastException。如果坐標不在範圍內,或者 obj 的大小不足以容納像素資料,則拋出 ArrayIndexOutOfBoundsException。
SampleModel 中的 setDataElementsx - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。obj - 套件含像素資料的基本陣列。data - 套件含圖像資料的 DataBuffer。getDataElements(int, int, Object, DataBuffer)
public void setPixel(int x,
int y,
int[] iArray,
DataBuffer data)
SampleModel 中的 setPixelx - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。iArray - int 陣列中的輸入樣本。data - 套件含圖像資料的 DataBuffer。getPixel(int, int, int[], DataBuffer)
public void setPixels(int x,
int y,
int w,
int h,
int[] iArray,
DataBuffer data)
SampleModel 中的 setPixelsx - 左上角像素位置的 X 坐標。y - 左上角像素位置的 Y 坐標。w - 像素矩形的寬度。h - 像素矩形的高度。iArray - int 陣列中的輸入樣本。data - 套件含圖像資料的 DataBuffer。getPixels(int, int, int, int, int[], DataBuffer)
public void setSample(int x,
int y,
int b,
int s,
DataBuffer data)
SampleModel 中的 setSamplex - 像素位置的 X 坐標。y - 像素位置的 Y 坐標。b - 要設置的 band。s - int 形式的輸入樣本。data - 套件含圖像資料的 DataBuffer。getSample(int, int, int, DataBuffer)
public void setSamples(int x,
int y,
int w,
int h,
int b,
int[] iArray,
DataBuffer data)
SampleModel 中的 setSamplesx - 左上角像素位置的 X 坐標。y - 左上角像素位置的 Y 坐標。w - 像素矩形的寬度。h - 像素矩形的高度。b - 要設置的 band。iArray - int 陣列中的輸入樣本。data - 套件含圖像資料的 DataBuffer。getSamples(int, int, int, int, int, int[], DataBuffer)public boolean equals(Object o)
Object 複製的描述
equals 方法在非空(null)物件參考上實作相等關係:
x,x.equals(x) 都應返回 true。
x 和 y,當且僅當 y.equals(x) 返回 true 時,x.equals(y) 才應返回 true。
x、y 和 z,如果 x.equals(y) 返回 true,並且 y.equals(z) 返回 true,那麼 x.equals(z) 應返回 true。
x 和 y,多次調用 x.equals(y) 始終返回 true 或始終返回 false,前提是物件上 equals 比較中所用的資訊沒有被修改。
x,x.equals(null) 都應返回 false。
Object 類別的 equals 方法實作物件上差別可能性最大的相等關係;即,對於任何非空(null)參考值 x 和 y,當且僅當 x 和 y 參考同一個物件時,此方法才返回 true(x == y 具有值 true)。
注意:當此方法被覆寫時,通常有必要覆寫 hashCode 方法,以維護 hashCode 方法的常規協定,該協定宣告相等物件必須具有相等的雜湊碼。
Object 中的 equalso - 要與之比較的參考物件。
true;否則返回 false。Object.hashCode(),
Hashtablepublic int hashCode()
Object 複製的描述java.util.Hashtable 提供的雜湊表)的性能。
hashCode 的常規協定是:
hashCode 方法都必須產生相同的整數結果。
Object.equals(java.lang.Object) 方法,兩個物件不相等,那麼對這兩個物件中的任一物件上調用 hashCode 方法不 要求一定產生不同的整數結果。但是,開發人員應該意識到,為不相等的物件產生不同整數結果可以提高雜湊表的性能。
實際上,由 Object 類別定義的 hashCode 方法確實會針對不同的物件返回不同的整數。(這一般是通過將該物件的內部位址轉換成一個整數來實作的,但是 JavaTM 程式語言不需要這種實作技巧。)
Object 中的 hashCodeObject.equals(java.lang.Object),
Hashtable
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。