public class MemoryImageSource extends Object implements ImageProducer
int w = 100;
int h = 100;
int pix[] = new int[w * h];
int index = 0;
for (int y = 0; y < h; y++) {
int red = (y * 255) / (h - 1);
for (int x = 0; x < w; x++) {
int blue = (x * 255) / (w - 1);
pix[index++] = (255 << 24) | (red << 16) | blue;
}
}
Image img = createImage(new MemoryImageSource(w, h, pix, 0, w));
また、MemoryImageSourceは、時間とともに変化して、アニメーションやカスタム・レンダリングを可能にするメモリー・イメージを管理する機能を持ちます。次に、アニメーション・ソース、およびデータの信号変化の設定方法の例を示します(Garth DickieによるMemoryAnimationSourceDemoからの適用)。
int pixels[];
MemoryImageSource source;
public void init() {
int width = 50;
int height = 50;
int size = width * height;
pixels = new int[size];
int value = getBackground().getRGB();
for (int i = 0; i < size; i++) {
pixels[i] = value;
}
source = new MemoryImageSource(width, height, pixels, 0, width);
source.setAnimated(true);
image = createImage(source);
}
public void run() {
Thread me = Thread.currentThread( );
me.setPriority(Thread.MIN_PRIORITY);
while (true) {
try {
Thread.sleep(10);
} catch( InterruptedException e ) {
return;
}
// Modify the values in the pixels array at (x, y, w, h)
// Send the new data to the interested ImageConsumers
source.newPixels(x, y, w, h);
}
}
ImageProducer
コンストラクタと説明 |
---|
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
byte配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props)
byte配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)
整数型配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props)
整数型配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
MemoryImageSource(int w, int h, int[] pix, int off, int scan)
デフォルトRGBカラー・モデルの整数型配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props)
デフォルトRGBカラー・モデルの整数型配列を使用してImageオブジェクト・データを生成するImageProducerオブジェクトを構築します。
|
修飾子と型 | メソッドと説明 |
---|---|
void |
addConsumer(ImageConsumer ic)
このイメージのデータの配信対象となっているコンシューマのリストにImageConsumerを追加します。
|
boolean |
isConsumer(ImageConsumer ic)
現在このイメージのデータの配信対象となっているコンシューマのリストにImageConsumerがあるかどうかを判定します。
|
void |
newPixels()
このイメージ・データを現在要求するImageConsumerにピクセルの新しいバッファ全体を送出し、アニメーション・フレームの送出が完了したことを通知します。
|
void |
newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
新しいbyte配列を、このイメージのピクセルを保持するように変更します。
|
void |
newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
新しいint配列を、このイメージのピクセルを保持するように変更します。
|
void |
newPixels(int x, int y, int w, int h)
このイメージのデータを現在要求するImageConsumerにピクセルの矩形領域バッファを送出し、アニメーション・フレームの送出が完了したことを通知します。
|
void |
newPixels(int x, int y, int w, int h, boolean framenotify)
このイメージのデータを現在要求するImageConsumerに、ピクセルの矩形領域バッファを送出します。
|
void |
removeConsumer(ImageConsumer ic)
このイメージのデータの配信対象となっているコンシューマのリストからImageConsumerを削除します。
|
void |
requestTopDownLeftRightResend(ImageConsumer ic)
指定されたImageConsumerに、上から下、左から右の順でもう1回イメージ・データを配信し直すように要求します。
|
void |
setAnimated(boolean animated)
animatedパラメータに従って、このメモリー・イメージをマルチフレームのアニメーションまたはシングル・フレームの静止イメージに変更します。
|
void |
setFullBufferUpdates(boolean fullbuffers)
変更があったときはいつでもピクセルの完全なバッファを送出し、このアニメーション化メモリー・イメージを常に更新するかどうかを指定します。
|
void |
startProduction(ImageConsumer ic)
このイメージ・データを要求するコンシューマのリストにImageConsumerを追加し、ImageConsumerインタフェース経由でただちにイメージ・データの転送を開始します。
|
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さcm
- 指定されたColorModel
pix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さcm
- 指定されたColorModel
pix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離props
- ImageProducer
がイメージ処理で使うプロパティ・リストComponent.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さcm
- 指定されたColorModel
pix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離Component.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さcm
- 指定されたColorModel
pix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離props
- ImageProducer
がイメージ処理で使うプロパティ・リストComponent.createImage(java.awt.image.ImageProducer)
public MemoryImageSource(int w, int h, int[] pix, int off, int scan)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さpix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離Component.createImage(java.awt.image.ImageProducer)
, ColorModel.getRGBdefault()
public MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props)
w
- ピクセルの矩形の幅h
- ピクセルの矩形の高さpix
- ピクセルの配列off
- 最初のピクセルを配列のどこに格納するかを表すオフセットscan
- 配列内のあるピクセル行から次のピクセル行までの距離props
- ImageProducer
がイメージ処理で使うプロパティ・リストComponent.createImage(java.awt.image.ImageProducer)
, ColorModel.getRGBdefault()
public void addConsumer(ImageConsumer ic)
addConsumer
、インタフェース: ImageProducer
ic
- 指定されたImageConsumer
NullPointerException
- 指定されたImageConsumer
がnullの場合ImageConsumer
public boolean isConsumer(ImageConsumer ic)
isConsumer
、インタフェース: ImageProducer
ic
- 指定されたImageConsumer
ImageConsumer
がリスト上にある場合はtrue
、そうでない場合はfalse
。ImageConsumer
public void removeConsumer(ImageConsumer ic)
removeConsumer
、インタフェース: ImageProducer
ic
- 指定されたImageConsumer
ImageConsumer
public void startProduction(ImageConsumer ic)
startProduction
、インタフェース: ImageProducer
ic
- ImageConsumerインタフェースを介した、指定されたImageConsumer
イメージ・データ。ImageConsumer
public void requestTopDownLeftRightResend(ImageConsumer ic)
requestTopDownLeftRightResend
、インタフェース: ImageProducer
ic
- 指定されたImageConsumer
ImageConsumer
public void setAnimated(boolean animated)
このメソッドは、すべてのImageConsumerが正常なマルチフレーム・データを受け取ることを保証するために、MemoryImageSourceの構築後ただちに、イメージが生成される前に呼び出す必要があります。このフラグを設定する前に、ImageConsumerをこのImageProducerに追加すると、接続したときに利用可能であったピクセル・データのスナップショットだけがImageConsumerから参照されます。
animated
- そのイメージがマルチフレーム・アニメーションの場合はtrue
public void setFullBufferUpdates(boolean fullbuffers)
このメソッドは、MemoryImageSourceの構築後ただちに、イメージが作成される前に呼び出され、すべてのImageConsumerに正常なピクセル転送情報を受け渡します。
fullbuffers
- 完全なピクセル・バッファを常に送出する場合はtrue
setAnimated(boolean)
public void newPixels()
public void newPixels(int x, int y, int w, int h)
x
- 送出されるピクセルの矩形の左上隅のX座標y
- 送出されるピクセルの矩形の左上隅のY座標w
- 送出されるピクセルの矩形の幅h
- 送出されるピクセルの矩形の高さnewPixels(int, int, int, int, boolean)
, ImageConsumer
, setAnimated(boolean)
, setFullBufferUpdates(boolean)
public void newPixels(int x, int y, int w, int h, boolean framenotify)
x
- 送出されるピクセルの矩形の左上隅のX座標y
- 送出されるピクセルの矩形の左上隅のY座標w
- 送出されるピクセルの矩形の幅h
- 送出されるピクセルの矩形の高さframenotify
- コンシューマにSINGLEFRAMEDONE
通知を送出する場合はtrue
ImageConsumer
, setAnimated(boolean)
, setFullBufferUpdates(boolean)
public void newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
newpix
- 新しいピクセル配列newmodel
- 指定されたColorModel
offset
- 配列へのオフセットscansize
- 配列内のあるピクセル行から次のピクセル行までの距離newPixels(int, int, int, int, boolean)
, setAnimated(boolean)
public void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
newpix
- 新しいピクセル配列newmodel
- 指定されたColorModel
offset
- 配列へのオフセットscansize
- 配列内のあるピクセル行から次のピクセル行までの距離newPixels(int, int, int, int, boolean)
, setAnimated(boolean)
バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.Use is subject to license termsDocumentation Redistribution Policyも参照してください。