1、Graphics
drawImage()的一些重载版
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) //绘制与当前可用的指定图像一样多的指定区域,即时缩放它以适合目标可绘制表面的指定区域。
abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) //绘制与当前可用的指定图像一样多的指定区域,即时缩放它以适合目标可绘制表面的指定区域。
abstract boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) //绘制已经缩放以适合指定矩形内部的指定图像。
abstract boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) //绘制已经缩放以适合指定矩形内部的指定图像。
abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) //绘制尽可能多的指定图像。
abstract boolean drawImage(Image img, int x, int y, ImageObserver observer) //绘制尽可能多的指定图像。
java.awt. Image提供返回其本身缩放表示的方法,结果就是想要得到的高速缓存图像。在该方法中,使用了三个整型参数:Image . getScaledInstance (int,int,int)。第一和第二个整型参数用来指明图像的宽度和高度,而第三个integer参数指明缩放图像的算法类型。
图像的缩放算法常量:
SCALE_DEFAULT //使用缺省的图像缩放算法
SCALE_FAST //被缩放的图像的速度优先于平滑
SCALE_SMOOTH //提高平滑优先于提高速度
SCALE_REPLICATE //使用由ReplicateScaleFilter提供的算法
SCALE_AVERAGING //使用由AreaAveragingScaleFilter提供的算法
2、抓取像素
PixelGrabber类:是在给定图像中抓取矩形区域中的像素的 ImageConsumer接口的一个实现。
构造方法:
PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize) //创建一个PixelGrabber对象,从指定的ImageProducer生成的图像中抓取(x,y,w,h)矩形像素部分到给定数组中。
PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB) //创建PixelGrabber对象以从指定图像中抓取(x,y,w,h)矩形像素部分。
PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize) //创建PixelGrabber对象以从指定图像中抓取(x,y,w,h)矩形像素部分到给定数组中。
方法:
void abortGrabbing() //请求PixelGrabber中止图像提取。
ColorModel getColorModel() //获取存储在数组中的像素的ColorModel。
int getHeight() //获取像素缓冲区的高度(调整图像高度后)。
Object getPixels() //获取像素缓冲区。
int getStatus() //返回像素的状态。
int getWidth() //获取像素缓冲区的宽度(调整图像宽度后)。
boolean grabPixels() //请求Image或ImageProducer开始提供像素,并等待感兴趣的矩形中的所有像素被传递。
boolean grabPixels(long ms) //请求Image或ImageProducer开始传送像素,并等待传递感兴趣的矩形中的所有像素,或者直到指定的超时时间结束。
void imageComplete(int status) //imageComplete方法是ImageConsumer API的一部分,此类必须实现它以检索像素。
void setColorModel(ColorModel model) //setColorModel方法是ImageConsumer API的一部分,该类必须实现它才能检索像素。
void setDimensions(int width, int height) //setDimensions方法是ImageConsumer API的一部分,此类必须实现它才能检索像素。
void setHints(int hints) //setHints方法是ImageConsumer API的一部分,该类必须实现它才能检索像素
void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, byte[] pixels, int srcOff, int srcScan) //setPixels方法是ImageConsumer API的一部分,该类必须实现它才能检索像素。
void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, int[] pixels, int srcOff, int srcScan) //setPixels方法是ImageConsumer API的一部分,该类必须实现它才能检索像素。
void setProperties(Hashtable<?,?> props) //setProperties方法是ImageConsumer API的一部分,此类必须实现该API才能检索像素。
void startGrabbing() //请求PixelGrabber开始获取像素。
int status() //返回像素的状态。
3、内存图像源
Java.awt.image.MemoryImageSource实现 ImageProducer接口,并且可以从像素数组中生产图像的位,将像素数组转换为图像的基础结构。
构造方法:
MemoryImageSource(int w, int h, int[] pix, int off, int scan) //构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。
MemoryImageSource(int w, int h, int[] pix, int off, int scan, Hashtable<?,?> props) //构造一个ImageProducer对象,该对象使用默认RGB ColorModel中的整数数组来为Image对象生成数据。
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan) //构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。
MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan, Hashtable<?,?> props) //构造一个ImageProducer对象,该对象使用字节数组为Image对象生成数据。
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan) //构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。
MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off, int scan, Hashtable<?,?> props) //构造一个ImageProducer对象,该对象使用整数数组为Image对象生成数据。
- 每种构造器的前两个参数都是用来指明图像的宽度和高度。所有的构造器获得一个bytes数组或integers 数组,用来生产图像,除此之外还传递偏移量和scansize。
- 如果在构造器中没有传递颜色模式,则数组中的像素被假定存贮为RGB格式。构造器同时也提供指明图像属性散列表的变体,以得到更多的关于图像消费者属性的信息。
方法:
void addConsumer(ImageConsumer ic) //将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中。
boolean isConsumer(ImageConsumer ic) //确定ImageConsumer是否位于当前对此图像的数据感兴趣的使用者列表中。
void newPixels() //向当前对此图像的数据感兴趣的任何ImageConsumers发送一个全新的像素缓冲区,并通知它们动画帧已完成。
void newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize) //更改新的字节数组以保存此图像的像素。
void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize) //更改为新的int数组以保存此图像的像素。
void newPixels(int x, int y, int w, int h) //将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers,并通知它们动画帧已完成。
void newPixels(int x, int y, int w, int h, boolean framenotify) //将像素缓冲区的矩形区域发送到当前对此图像的数据感兴趣的任何ImageConsumers。
void removeConsumer(ImageConsumer ic) //从对此图像的数据感兴趣的使用者列表中删除ImageConsumer
void requestTopDownLeftRightResend(ImageConsumer ic) //请求给定的ImageConsumer以自上而下,左右顺序再次传递图像数据。
void setAnimated(boolean animated) //根据动画参数将此内存图像更改为多帧动画或单帧静态图像。
void setFullBufferUpdates(boolean fullbuffers) //指定是否应始终通过在发生更改时发送完整的像素缓冲区来更新此动画内存图像。
void startProduction(ImageConsumer ic) //将ImageConsumer添加到对此图像的数据感兴趣的使用者列表中,并立即通过ImageConsumer界面开始传送图像数据。
4、使用MemoryImageSource裁剪图像,内存图像源和动画
就是使用上面两个类的方法的应用,自己琢磨。或者看《java2图形设计卷1:AWT》中的相关章节代码例子。
这篇博客深入探讨了Java中的图像处理技术,包括Graphics类的drawImage()方法的不同重载版本,用于图像的绘制和缩放。同时介绍了PixelGrabber类用于抓取和操作像素,以及MemoryImageSource类如何生成和裁剪内存中的图像。此外,还讨论了内存图像源在动画制作中的应用。
475

被折叠的 条评论
为什么被折叠?



