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 - æå®ãããColorModelpix - ãã¯ã»ã«ã®é
å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 - æå®ãããColorModelpix - ãã¯ã»ã«ã®é
å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 - æå®ãããColorModelpix - ãã¯ã»ã«ã®é
å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 - æå®ãããColorModelpix - ãã¯ã»ã«ã®é
å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ãã€ã³ã¿ãã§ãŒã¹ImageProduceric - æå®ãããImageConsumerNullPointerException - æå®ãããImageConsumerãnullã®å ŽåImageConsumerpublic boolean isConsumer(ImageConsumer ic)
isConsumerãã€ã³ã¿ãã§ãŒã¹ImageProduceric - æå®ãããImageConsumerImageConsumerããªã¹ãäžã«ããå Žåã¯trueãããã§ãªãå Žåã¯falseãImageConsumerpublic void removeConsumer(ImageConsumer ic)
removeConsumerãã€ã³ã¿ãã§ãŒã¹ImageProduceric - æå®ãããImageConsumerImageConsumerpublic void startProduction(ImageConsumer ic)
startProductionãã€ã³ã¿ãã§ãŒã¹ImageProduceric - ImageConsumerã€ã³ã¿ãã§ãŒã¹ãä»ãããæå®ãããImageConsumerã€ã¡ãŒãžã»ããŒã¿ãImageConsumerpublic void requestTopDownLeftRightResend(ImageConsumer ic)
requestTopDownLeftRightResendãã€ã³ã¿ãã§ãŒã¹ImageProduceric - æå®ãããImageConsumerImageConsumerpublic void setAnimated(boolean animated)
ãã®ã¡ãœããã¯ããã¹ãŠã®ImageConsumerãæ£åžžãªãã«ããã¬ãŒã ã»ããŒã¿ãåãåãããšãä¿èšŒããããã«ãMemoryImageSourceã®æ§ç¯åŸãã ã¡ã«ãã€ã¡ãŒãžãçæãããåã«åŒã³åºãå¿ èŠããããŸãã ãã®ãã©ã°ãèšå®ããåã«ãImageConsumerããã®ImageProducerã«è¿œå ãããšãæ¥ç¶ãããšãã«å©çšå¯èœã§ãã£ããã¯ã»ã«ã»ããŒã¿ã®ã¹ãããã·ã§ããã ããImageConsumerããåç §ãããŸãã
animated - ãã®ã€ã¡ãŒãžããã«ããã¬ãŒã ã»ã¢ãã¡ãŒã·ã§ã³ã®å Žåã¯truepublic void setFullBufferUpdates(boolean fullbuffers)
ãã®ã¡ãœããã¯ãMemoryImageSourceã®æ§ç¯åŸãã ã¡ã«ãã€ã¡ãŒãžãäœæãããåã«åŒã³åºããããã¹ãŠã®ImageConsumerã«æ£åžžãªãã¯ã»ã«è»¢éæ å ±ãåãæž¡ããŸãã
fullbuffers - å®å
šãªãã¯ã»ã«ã»ãããã¡ãåžžã«éåºããå Žåã¯truesetAnimated(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éç¥ãéåºããå Žåã¯trueImageConsumer, setAnimated(boolean), setFullBufferUpdates(boolean)public void newPixels(byte[] newpix,
ColorModel newmodel,
int offset,
int scansize)
newpix - æ°ãããã¯ã»ã«é
ånewmodel - æå®ãããColorModeloffset - é
åãžã®ãªãã»ããscansize - é
åå
ã®ãããã¯ã»ã«è¡ããæ¬¡ã®ãã¯ã»ã«è¡ãŸã§ã®è·é¢newPixels(int, int, int, int, boolean), setAnimated(boolean)public void newPixels(int[] newpix,
ColorModel newmodel,
int offset,
int scansize)
newpix - æ°ãããã¯ã»ã«é
ånewmodel - æå®ãããColorModeloffset - é
åãžã®ãªãã»ããscansize - é
åå
ã®ãããã¯ã»ã«è¡ããæ¬¡ã®ãã¯ã»ã«è¡ãŸã§ã®è·é¢newPixels(int, int, int, int, boolean), setAnimated(boolean) ãã°ãŸãã¯æ©èœãéä¿¡
詳现ãªAPIãªãã¡ã¬ã³ã¹ããã³éçºè
ããã¥ã¡ã³ãã«ã€ããŠã¯ãJava SEã®ããã¥ã¡ã³ããåç
§ããŠãã ããã ãã®ããã¥ã¡ã³ãã«ã¯ãæŠå¿µçãªæŠèŠãçšèªã®å®çŸ©ãåé¿æ¹æ³ãæå¹ãªã³ãŒãäŸãªã©ã®ãéçºè
ã察象ã«ãããã詳现ãªèª¬æãå«ãŸããŠããŸãã
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Documentation Redistribution Policyãåç
§ããŠãã ããã