e666. 创建缓冲图像

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

原文地址:https://www.cnblogs.com/borter/p/9575500.html

时间: 2024-10-15 13:59:37

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

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

This example demonstrates how to convert a byte array of pixel values that are indices to a color table into a BufferedImage. In particular, the example generates the Mandelbrot set in a byte buffer and combines this data with a SampleModel, ColorMod

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

An Image object cannot be converted to a BufferedImage object. The closest equivalent is to create a buffered image and then draw the image on the buffered image. This example defines a method that does this. // This method returns a buffered image w

e675. 翻转缓冲图像

// To create a buffered image, see e666 创建缓冲图像 // Flip the image vertically AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE

AJAX & JavaScript Barcode Generator集成到AJAX Web应用程序创建条形码图像

AJAX & JavaScript Barcode Generator是原生的JavaScript,用于创建条形码图像,它可以很容易地集成到AJAX Web应用程序,Oracle报表和HTML中.因为它是原生的JavaScript ,所以不需要安装任何额外的组件,字体或插件来创建条形码,它还是功能完善的JavaScript条形码生成空控件. 具体功能: 多种条形码类型被一个单个的产品所支持. 多地区兼容性-本产品兼容了所有的语言和地区设置,包括Windows的双字节版本,如用于中国和日本,以及亚

报表上创建条形码图像的条码控件Native MS Access Barcode Generator

Native MS Access Barcode Generator条形码控件是一个VBA模块,可以方便地嵌入到微软Access数据库中,用于在报表上创建条形码图像.一旦被安装到一个数据库中,创建条形码时就不需要安装其它任何字体或组件:它是一个完整的.与数据库一起使用的条形码生成器,即使当它发布以后也一样. 具体功能: Native Access Barcode Generator产品是为那些希望不依赖任何外部设备,而将条形码功能纳入到数据库和应用程序的Access开发者而准备的.非开发人员和最

报表上创建条形码图像的条形码控件Native MS Access Barcode Generator

Native MS Access Barcode Generator是一个VBA模块,可以方便地嵌入到微软Access数据库中,用于在报表上创建条形码图像.一旦被安装到一个数据库中,创建条形码时就不需要安装其它任何字体或组件:它是一个完整的.与数据库一起使用的条形码生成器,即使当它发布以后也一样. 具体功能: Native Access Barcode Generator产品是为那些希望不依赖任何外部设备,而将条形码功能纳入到数据库和应用程序的Access开发者而准备的.非开发人员和最终用户可能

【OpenCV入门教程之六】 创建Trackbar & 图像对比度、亮度值调整(转)

本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/21479533 作者:毛星云(浅墨)    邮箱: [email protected] 写作当前博文时配套使用的OpenCV版本: 2.4.8 这篇文章中我们一起学习了如何在OpenCV中用createTrackbar函数创建和使用轨迹条,以及图像对比度.亮度值的动态调整. 文章首先详细讲解了OpenCV2.0中的新版创建轨迹条的函数c

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

http://blog.csdn.net/poem_qianmo/article/details/21479533 [OpenCV入门教程之六] 创建Trackbar & 图像对比度.亮度值调整 标签: opencvvs2010c++图像处理 2014-03-18 21:43 43189人阅读 评论(99) 收藏 举报  分类: [OpenCV](18)  目录(?)[+] 本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qian

CSS创建透明图像

CSS 图像透明/不透明 CSS Opacity属性是W3C的CSS3建议的一部分.创建透明图像 - 悬停效果创建一个透明图像CSS3中属性的透明度是 opacity.img{ opacity:0.4; filter:alpha(opacity=40); /* IE8 及其更早版本 */}IE9,Firefox,Chrome,Opera,和Safari浏览器使用透明度属性可以将图像变的不透明. Opacity属性值从0.0 - 1.0.值越小,使得元素更加透明.IE8和早期版本使用滤镜:alph