博客
关于我
javaGUI学习15:AWT-无过滤图像处理
阅读量:328 次
发布时间:2019-03-04

本文共 3143 字,大约阅读时间需要 10 分钟。

Graphics类中的绘图方法

在Java AWT中,Graphics类提供了多个drawImage方法用于绘制图像。这些方法允许开发者以不同的方式缩放和绘制图像,满足不同的应用需求。以下是这些方法的简要说明:

  • 缩放绘图

    drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer)
    该方法绘制与当前可用的指定图像一样多的指定区域,并按比例缩放以适合目标可绘制表面。

  • 直接缩放绘图

    drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer)
    该方法绘制已经预先缩放好的图像,以适合指定的矩形区域。

  • 无背景色绘图

    drawImage(Image img, int x, int y, int width, int height, ImageObserver observer)
    该方法绘制尽可能多的指定图像,不使用背景色。

  • 默认缩放算法

    Image.getScaledInstance(int width, int height, int scale)
    该方法返回一个缩放后的图像实例,支持三种缩放算法:SCALE_DEFAULT(默认)、SCALE_FAST(速度优先)、SCALE_SMOOTH(平滑优先)和SCALE_REPLICATE(复制算法)。

  • PixelGrabber类:像素抓取接口

    PixelGrabber是一个实现ImageConsumer接口的类,用于从图像中抓取像素。它提供了多种方法来控制和获取像素数据。

    构造方法

    • PixelGrabber(ImageProducer ip, int x, int y, int w, int h, int[] pix, int off, int scansize)
      从指定的ImageProducer中抓取指定区域的像素,并将结果存储在给定的数组中。
    • PixelGrabber(Image img, int x, int y, int w, int h, boolean forceRGB)
      从指定图像中抓取指定区域的像素,默认使用RGB色彩模型。
    • PixelGrabber(Image img, int x, int y, int w, int h, int[] pix, int off, int scansize)
      从指定图像中抓取指定区域的像素,并将结果存储在给定的数组中。

    方法

    • void abortGrabbing()
      请求中止像素抓取操作。
    • ColorModel getColorModel()
      获取存储在像素数组中的颜色模型。
    • int getHeight()
      获取像素缓冲区的高度。
    • Object getPixels()
      获取像素缓冲区的内容。
    • int getStatus()
      返回当前像素抓取的状态。
    • int getWidth()
      获取像素缓冲区的宽度。
    • boolean grabPixels()
      请求开始像素抓取操作。
    • boolean grabPixels(long ms)
      请求开始像素抓取操作,并等待指定时间内完成。
    • void imageComplete(int status)
      通知像素抓取完成的状态。
    • void setColorModel(ColorModel model)
      设置用于获取像素的颜色模型。
    • void setDimensions(int width, int height)
      设置像素缓冲区的维度。
    • void setHints(int hints)
      提供关于像素抓取的提示信息。
    • void setPixels(int srcX, int srcY, int srcW, int srcH, ColorModel model, byte[] pixels, int srcOff, int srcScan)
      将像素数据设置到指定的缓冲区中。
    • void setProperties(Hashtable props)
      设置与像素抓取相关的属性。
    • void startGrabbing()
      请求开始像素抓取操作。
    • int status()
      返回当前像素抓取的状态。

    MemoryImageSource类:内存图像源

    MemoryImageSource是一个实现ImageProducer接口的类,用于从像素数组中生成图像数据。它支持多种构造方法,以适应不同的使用场景。

    构造方法

    • MemoryImageSource(int w, int h, int[] pix, int off, int scan)
      创建一个内存图像源,使用默认RGB颜色模型。
    • MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off, int scan)
      创建一个内存图像源,使用指定的颜色模型和字节数组。
    • 其他构造方法类似于上述方法,提供了更多的灵活性。

    方法

    • void addConsumer(ImageConsumer ic)
      ImageConsumer添加到对此图像数据感兴趣的使用者列表中。
    • boolean isConsumer(ImageConsumer ic)
      检查指定的ImageConsumer是否在使用者列表中。
    • void newPixels()
      向所有订阅者提供一个新的像素缓冲区。
    • void newPixels(byte[] newpix, ColorModel newmodel, int offset, int scansize)
      更新像素缓冲区的内容。
    • void newPixels(int[] newpix, ColorModel newmodel, int offset, int scansize)
      更新像素缓冲区的内容。
    • void newPixels(int x, int y, int w, int h)
      向所有订阅者提供指定区域的像素缓冲区。
    • void newPixels(int x, int y, int w, int h, boolean framenotify)
      向所有订阅者提供指定区域的像素缓冲区,并通知动画完成。
    • void removeConsumer(ImageConsumer ic)
      从使用者列表中移除指定的ImageConsumer
    • void requestTopDownLeftRightResend(ImageConsumer ic)
      请求重新传输像素数据,按从上到下、从左到右的顺序。
    • void setAnimated(boolean animated)
      指定是否将此内存图像作为多帧动画或单帧静态图像。
    • void setFullBufferUpdates(boolean fullbuffers)
      指定是否始终通过完整的像素缓冲区来更新图像。
    • void startProduction(ImageConsumer ic)
      将指定的ImageConsumer添加到使用者列表中,并开始传输像素数据。

    使用MemoryImageSource裁剪图像

    通过MemoryImageSourcePixelGrabber类,可以轻松地从内存中生成图像,并进行裁剪和像素抓取操作。这种方法特别适用于需要动态调整图像大小或进行像素级处理的场景。

    转载地址:http://lalq.baihongyu.com/

    你可能感兴趣的文章
    Oracle Spatial GeoRaster 金字塔栅格存储
    查看>>
    Oracle spatial 周边查询SQL
    查看>>
    Oracle Spatial空间数据库建立
    查看>>
    UML— 活动图
    查看>>
    oracle sqlplus已停止工作,安装完成客户端后sqlplus报“段错误”
    查看>>
    oracle SQLserver 函数
    查看>>
    oracle sql分组(group,根据多个内容分组)在select之后from之前 再进行select查询,复杂子查询的使用
    查看>>
    Oracle Statspack分析报告详解(一)
    查看>>
    oracle tirger_在Oracle中,临时表和全局临时表有什么区别?
    查看>>
    Oracle Validated Configurations 安装使用 说明
    查看>>
    oracle where 条件的执行顺序分析1
    查看>>
    oracle 中的 CONCAT,substring ,MINUS 用法
    查看>>
    Oracle 中的 decode
    查看>>
    oracle 中表一对多取多方的最新的一条数据
    查看>>
    oracle 使用 PL/SQL Developer创建表并插入单条、多条数据
    查看>>
    oracle 使用leading, use_nl, rownum调优
    查看>>
    oracle 修改字段类型方法
    查看>>
    Oracle 修改数据库表数据提交之后进行回滚
    查看>>
    UML-总结
    查看>>
    oracle 内存参数示意图
    查看>>