A buffered image is a type of image whose pixels can be modified. For example, you can draw on a buffered image and then draw the resulting buffered image on the screen or save it to a file. A buffered image supports many formats for storing pixels. Although a buffered image of any format can be drawn on the screen, it is best to choose a format that is the most compatible with the screen to allow efficient drawing. This example demonstrates several ways of creating a buffered image.

If the buffered image will not be drawn, it can simply be constructed with a specific format; TYPE_INT_RGB and TYPE_INT_ARGB are typically used. See BufferedImage for a list of available formats.

See also e667 在给定图像中创建缓冲图像.

    int width = 100;
int height = 100; // Create buffered image that does not support transparency
BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // Create a buffered image that supports transparency
bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

These examples create buffered images that are compatible with the screen:

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration(); // Create an image that does not support transparency
bimage = gc.createCompatibleImage(width, height, Transparency.OPAQUE); // Create an image that supports transparent pixels
bimage = gc.createCompatibleImage(width, height, Transparency.BITMASK); // Create an image that supports arbitrary levels of transparency
bimage = gc.createCompatibleImage(width, height, Transparency.TRANSLUCENT);

A screen compatible buffered image can also be created from a graphics context:

    public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
int width = 100;
int height = 100; // Create an image that does not support transparency
BufferedImage bimage = g2d.getDeviceConfiguration().createCompatibleImage(
width, height, Transparency.OPAQUE); // Create an image that supports transparent pixels
bimage = g2d.getDeviceConfiguration().createCompatibleImage(
width, height, Transparency.BITMASK); // Create an image that supports arbitrary levels of transparency
bimage = g2d.getDeviceConfiguration().createCompatibleImage(
width, height, Transparency.TRANSLUCENT);
}

One last way of 创建缓冲图像 is using Component.createImage(). This method can be used only if the component is visible on the screen. Also, this method returns buffered images that do not support transparent pixels.

    BufferedImage bimage = (BufferedImage)component.createImage(width, height);
if (bimage == null) {
// The component is not visible on the screen
}
Related Examples

e666. 创建缓冲图像的更多相关文章

  1. e668. 在一组像素中创建缓冲图像

    This example demonstrates how to convert a byte array of pixel values that are indices to a color ta ...

  2. e667. 在给定图像中创建缓冲图像

    An Image object cannot be converted to a BufferedImage object. The closest equivalent is to create a ...

  3. e675. 翻转缓冲图像

    // To create a buffered image, see e666 创建缓冲图像 // Flip the image vertically AffineTransform tx = Aff ...

  4. PNG格式的图像文件,创建的图像的MIME类型的头部

    在安装完这三个组件后,还需要重新配置一次PHP,这也是你对采用DSO方式安装PHP感到庆幸的地方之一.运行make clean,然后在当前的配置中添加下面的内容: --with-gd=[/path/t ...

  5. 创建条形码图像易用的控制字符编码功能的条形码控件Native Crystal Reports Barcode Generator

    Native Crystal Reports Barcode Generator是一个对象,它可以很容易地被嵌入到一个Crystal Report中用于创建条形码图像.一旦此条形码被安装在一个报表中, ...

  6. opencv ,亮度调整【【OpenCV入门教程之六】 创建Trackbar & 图像对比度、亮度值调整

    http://blog.csdn.net/poem_qianmo/article/details/21479533 [OpenCV入门教程之六] 创建Trackbar & 图像对比度.亮度值调 ...

  7. 利用PIL库创建空白图像

    背景 最近,想自己生成带位置坐标的文字数据集来训练文本位置探测网络. 理想情况是,给文字加盐噪声,背景不需要加噪声,所以需要创建一个空白的背景.将文字放在空白背景上,然后利用opencv加噪声. 解决 ...

  8. 关于创建Web图像时应记住的五个要素

    1. 格式与下载速度 当前,Web上用的最广泛的三种格式是GIF.PNG和JPEG.我们的目标是选择质量最高,同时文件最小的格式. WebP图像格式 谷歌建立了另一种图像格式,名为WebP. 这种格式 ...

  9. 用截取的部分图像创建新图像--关于cvGetSubRect,cvGetImage的用法

    CvMat* cvGetSubRect(const CvArr* arr, CvMat* submat, CvRect rect)可以把截取图像中需要的区域存入矩阵.把IplImage *传给arr, ...

随机推荐

  1. tomcat在debug模式启动直接提示:弹框无法启动,无报错信息;但直接启动的话,就会有报错信息

    今天运行项目,Debug模式启动Tomcat,直接弹框:无法启动(翻译,因为后来整理,所以都忘记当时的截图) 后来尝试直接start,发现不弹框了,但是console有报出错信息. 类似以下错误 20 ...

  2. Oracle 11gR2数据库使用

    1很奇怪,不太懂原理 一.Oracle 12c创建用户是出现“ORA-65096: invalid common user or role name”的错误 - CalvinR http://www. ...

  3. 两种方式— 在hive SQL中传入参数

    第一种: sql = sql.format(dt=dt) 第二种: item_third_cate_cd_list = " 发发发 " ...... ""&qu ...

  4. HDU 4565 So Easy!(公式化简+矩阵)

    转载:http://www.klogk.com/posts/hdu4565/ 这里写的非常好,看看就知道了啊. 题意很easy.a,b,n都是正整数.求 Sn=⌈(a+b√)n⌉%m,(a−1)2&l ...

  5. Oracle行转列SQL

      -- Create table /*create table TEST_TABLE ( STUDENT VARCHAR2(200), SUBJECT VARCHAR2(200), GRADE NU ...

  6. Cocos2d-x添加Android手机震动

    这个震动需要调用adnroid系统的方法,所以需要C++调用java,JNI这里就不多做介绍了,需要的可以自己去查找下相关资料,如果你只是需要实现这个功能,相信你看完本文,应该就OK了! 1.首先,修 ...

  7. MVC,MVP 和 MVVM 的图示 转自阮一峰先生网络日志

    MVC,MVP 和 MVVM 的图示   作者: 阮一峰 复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛 ...

  8. maven-gpg-plugin:1.2:sign (sign-artifacts) on project jdbc-pool: Cannot obtain passphrase in batch mode或者是Plugin execution not covered by lifecycle configuration

    本解决方案转自:http://blog.csdn.net/tangximing123/article/details/21179467 执行 Maven install 时报错: Failed to ...

  9. spark streaming updateStateByKey 用法

    object NetworkWordCount { def main(args: Array[String]) { ) { System.err.println("Usage: Networ ...

  10. 【WPF】设置ListBox容器Item的流式布局

    需求:像下图那样显示把一组内容装入ListBox中显示.要求用WrapPanel横向布局,顺序如图中的数字. 问题:ListBox默认的布局是从上往下单列的,所以需要设置布局. <ListBox ...