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 with the contents of an image
public static BufferedImage toBufferedImage(Image image) {
if (image instanceof BufferedImage) {
return (BufferedImage)image;
} // This code ensures that all the pixels in the image are loaded
image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's
// implementation, see e661 确定图像中是否有透明像素
boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen
BufferedImage bimage = null;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
try {
// Determine the type of transparency of the new buffered image
int transparency = Transparency.OPAQUE;
if (hasAlpha) {
transparency = Transparency.BITMASK;
} // Create the buffered image
GraphicsDevice gs = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gs.getDefaultConfiguration();
bimage = gc.createCompatibleImage(
image.getWidth(null), image.getHeight(null), transparency);
} catch (HeadlessException e) {
// The system does not have a screen
} if (bimage == null) {
// Create a buffered image using the default color model
int type = BufferedImage.TYPE_INT_RGB;
if (hasAlpha) {
type = BufferedImage.TYPE_INT_ARGB;
}
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
} // Copy image to buffered image
Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image
g.drawImage(image, 0, 0, null);
g.dispose(); return bimage;
}
| Related Examples |
e667. 在给定图像中创建缓冲图像的更多相关文章
- e668. 在一组像素中创建缓冲图像
This example demonstrates how to convert a byte array of pixel values that are indices to a color ta ...
- e666. 创建缓冲图像
A buffered image is a type of image whose pixels can be modified. For example, you can draw on a buf ...
- e664. 在图像中获取子图像
// From an Image image = createImage(new FilteredImageSource(image.getSource(), new CropImageFilter( ...
- 在图像中隐藏数据:用 Python 来实现图像隐写术
什么是“隐写术”? 隐写术是将机密信息隐藏在更大的信息中,使别人无法知道隐藏信息的存在以及隐藏信息内容的过程.隐写术的目的是保证双方之间的机密交流.与隐藏机密信息内容的密码学不同,隐写术隐瞒了传达消息 ...
- e675. 翻转缓冲图像
// To create a buffered image, see e666 创建缓冲图像 // Flip the image vertically AffineTransform tx = Aff ...
- 关于创建Web图像时应记住的五个要素
1. 格式与下载速度 当前,Web上用的最广泛的三种格式是GIF.PNG和JPEG.我们的目标是选择质量最高,同时文件最小的格式. WebP图像格式 谷歌建立了另一种图像格式,名为WebP. 这种格式 ...
- gimp怎么移动选取中的图像并创建图层
gimp怎么移动选取中的图像并创建图层 https://jingyan.baidu.com/article/414eccf6bf4d6e6b431f0a3b.html 听语音 原创 | 浏览:1148 ...
- PHP动态图像的创建要如何实现呢?
with-gd=[/path/to/gd] --with-jpeg-dir=[/path/to/jpeg-6b] --with-t1lib=[/path/to/t1lib] 完成添加后执行make命 ...
- PNG格式的图像文件,创建的图像的MIME类型的头部
在安装完这三个组件后,还需要重新配置一次PHP,这也是你对采用DSO方式安装PHP感到庆幸的地方之一.运行make clean,然后在当前的配置中添加下面的内容: --with-gd=[/path/t ...
随机推荐
- C#--readlyonly关键字
字段可以使用readyonly修饰符声明.其作用类似声明一个字段为const,一旦值被设定就不能改变. const字段只能在字段的声明语句中初始化,而readyonly字段可以在下列任何位置设置它的值 ...
- STM32以太网ETH
注:stm32F1系列中F103片上不含MAC控制器,所以不支持以太网,只有F105和F107才支持
- mysql数据库以加索引方式提高性能
数据库查询速率慢的情况下可以给对应的表加上对应的索引,能够有效的提高查询效率,mysql数据库添加索引的SQL入下: ALTER TABLE `table_name` ADD INDEX index_ ...
- javascript Dictionary data structures
Dictionary常被称为数据字典,是一种用来保存键值对的数据结构,比如我们日常的电话本,就是一个Dictionary.我们通过键(名字),就可以访问到对应的值(电话号码).在C++与java中我们 ...
- javascript限定输入textarea输入长度
<textarea id="content" onkeyup="limitLength(this.value,'512','content')"> ...
- Firefox清空缓存的快捷键
有时候调试网页,需要清空缓存,常用的firefox清空缓存的快捷键: Shift+Ctrl+Delete
- 【Android】20.3 拍照和视频录制
分类:C#.Android.VS2015: 创建日期:2016-03-13 一.简介 Android提供的Camera有两个典型的版本,一个是在Android 5.0以前提供的,称为Camera:另一 ...
- maven(2)------maven构建项目
一 下载maven 官网地址: http://maven.apache.org/download.cgi 如图: 可以下载历史版本. 二 windows下maven配置 1. 解压下载后的包,解压后 ...
- ubantu 文件系统的目录结构
对于每一个Linux学习者来说,了解Linux文件系统的目录结构,是学好Linux的至关重要的一步.,深入了解linux文件目录结构的标准和每个目录的详细功能,对于我们用好linux系统只管重要, ...
- Chrome浏览器缓存查看工具-ChromeCacheView
最近想听一下最新的流行热歌,按着某网站的新歌排行榜逐首在巨鲸音乐网搜索下载,但相当一部分的歌曲还是没能下载到,逼不得已只能到百度MP3下载,在搜索结果中已经挑体积比较大的文件来下载了,但下载到的MP3 ...