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 |
e666. 创建缓冲图像的更多相关文章
- e668. 在一组像素中创建缓冲图像
This example demonstrates how to convert a byte array of pixel values that are indices to a color ta ...
- e667. 在给定图像中创建缓冲图像
An Image object cannot be converted to a BufferedImage object. The closest equivalent is to create a ...
- e675. 翻转缓冲图像
// To create a buffered image, see e666 创建缓冲图像 // Flip the image vertically AffineTransform tx = Aff ...
- PNG格式的图像文件,创建的图像的MIME类型的头部
在安装完这三个组件后,还需要重新配置一次PHP,这也是你对采用DSO方式安装PHP感到庆幸的地方之一.运行make clean,然后在当前的配置中添加下面的内容: --with-gd=[/path/t ...
- 创建条形码图像易用的控制字符编码功能的条形码控件Native Crystal Reports Barcode Generator
Native Crystal Reports Barcode Generator是一个对象,它可以很容易地被嵌入到一个Crystal Report中用于创建条形码图像.一旦此条形码被安装在一个报表中, ...
- opencv ,亮度调整【【OpenCV入门教程之六】 创建Trackbar & 图像对比度、亮度值调整
http://blog.csdn.net/poem_qianmo/article/details/21479533 [OpenCV入门教程之六] 创建Trackbar & 图像对比度.亮度值调 ...
- 利用PIL库创建空白图像
背景 最近,想自己生成带位置坐标的文字数据集来训练文本位置探测网络. 理想情况是,给文字加盐噪声,背景不需要加噪声,所以需要创建一个空白的背景.将文字放在空白背景上,然后利用opencv加噪声. 解决 ...
- 关于创建Web图像时应记住的五个要素
1. 格式与下载速度 当前,Web上用的最广泛的三种格式是GIF.PNG和JPEG.我们的目标是选择质量最高,同时文件最小的格式. WebP图像格式 谷歌建立了另一种图像格式,名为WebP. 这种格式 ...
- 用截取的部分图像创建新图像--关于cvGetSubRect,cvGetImage的用法
CvMat* cvGetSubRect(const CvArr* arr, CvMat* submat, CvRect rect)可以把截取图像中需要的区域存入矩阵.把IplImage *传给arr, ...
随机推荐
- DataGridView在Cell编辑状态响应回车键下的KeyPress/KeyDown/KeyUp事件
我们知道由于DataGridView的单元格DataGridCell处于编辑的时候,当你按Enter键,那么DataGridView是不会激发KewPress/KeyDown/KeyUp这些事件的,因 ...
- ps photoshop cc 2015 Extract Assets(生成器)切图大法
Extract Assets 是 Photoshop CC 2014 版本新增的一个特性,主要用来快速导出适用于 Web 和屏幕设计的资源,你可以用它导出 JPG.PNG.GIF,甚至是 SVG 图像 ...
- Google大牛分享的面试秘籍
我憋了很长时间想写点关于去Google面试的秘籍.不过我总是推迟,因为写出来的东西会让你抓狂.很可能是这样.如果按统计规律来定义“你”的话,这文章很可能让你不爽. 为啥呢?因为啊……好吧,对此我写首小 ...
- unity3d 通过添加rigidBody来指明物体是动态的,以避免cache开销
unity3d 通过添加rigidBody来指明物体是动态的,以避免cache开销. 如果不添加rigidBody,则unity会认为它是静态的,会对物理计算进行cache,但如果此物体实际上tran ...
- 使用xtrabackup(innobackupex)实现MySQL的热备
mysql 的热备http://www.178linux.com/10139http://www.linuxidc.com/Linux/2014-04/99671.htmhttp://634871.b ...
- linux快速进入全屏命令行模式
按CTRL+ALT+F1~6就可以了.F7是桌面环境.
- I/O Completion Ports
http://weblogs.asp.net/kennykerr/parallel-programming-with-c-part-4-i-o-completion-ports http://webl ...
- codeblocks主题修改(vim)
codeblocks的配置文件是default.conf,在Windows系统下,该文件在C:\Documents and Settings\Administrator\Application Dat ...
- Linux中查看CPU信息【转】
[转自]:http://blog.chinaunix.net/uid-23622436-id-3311579.html cat /proc/cpuinfo中的信息 processor 逻辑 ...
- 知乎:在卡内基梅隆大学 (Carnegie Mellon University) 就读是怎样一番体验?
转自:http://www.zhihu.com/question/24295398 知乎 Yu Zhang 知乎搜索 首页 话题 发现 消息 调查类问题名校就读体验修改 在卡内基梅隆大学 (Car ...