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. 在给定图像中创建缓冲图像的更多相关文章

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

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

  2. e666. 创建缓冲图像

    A buffered image is a type of image whose pixels can be modified. For example, you can draw on a buf ...

  3. e664. 在图像中获取子图像

    // From an Image image = createImage(new FilteredImageSource(image.getSource(), new CropImageFilter( ...

  4. 在图像中隐藏数据:用 Python 来实现图像隐写术

    什么是“隐写术”? 隐写术是将机密信息隐藏在更大的信息中,使别人无法知道隐藏信息的存在以及隐藏信息内容的过程.隐写术的目的是保证双方之间的机密交流.与隐藏机密信息内容的密码学不同,隐写术隐瞒了传达消息 ...

  5. e675. 翻转缓冲图像

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

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

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

  7. gimp怎么移动选取中的图像并创建图层

    gimp怎么移动选取中的图像并创建图层 https://jingyan.baidu.com/article/414eccf6bf4d6e6b431f0a3b.html 听语音 原创 | 浏览:1148 ...

  8. PHP动态图像的创建要如何实现呢?

    with-gd=[/path/to/gd] --with-jpeg-dir=[/path/to/jpeg-6b] --with-t1lib=[/path/to/t1lib]  完成添加后执行make命 ...

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

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

随机推荐

  1. gradle平级项目引用

    一.准备1. 新建一个gradle项目cc-core2. 新建一个gradle项目cc-util 二.场景项目cc-core引用项目cc-util 三.配置1. 项目cc-util被引用的项目什么都不 ...

  2. JS高级心法——作用域链

    首先我们来看两个js中的代码:    <script type="text/javascript"> var c=5; function t1(){ var d=6 f ...

  3. 更改Android应用程序的图标

    对于android应用程序的开发.默认的图标是一个小机器人,图片名称为ic_launcher.png. 可是,大多数开发人员是会将这个图标在开发过程中改为自己设计的icon. 把apk图标更改为自己设 ...

  4. css常用标签及属性

    css样式表常用的形式有三种,一.行内样式表.二.内部样式表.三.外部样式表 一. <p style="color:red;">nice to meet you< ...

  5. Shiro整合SSH开发3:配置Shiro认证后页面地址跳转问题(和详述不配置须要注意的问题)

         在视频教程中讲请求认证成功后跳转页面的问题是一笔带过的,可是我认为有必要单独写一篇相应的文章进行叙述.      我用了SSH来整合Shiro,在开发后验证的过程中,每次登陆后Shiro都会 ...

  6. XILINX之RAM使用指南(加个人总结)

    先加点自己的总结:真双口RAM可以在任意时间访问任意地址,两个端口的地址是一样的,即共享内存和地址.这就会带来一个问题:同时读写一个地址会发生冲突.基于这个点矛盾就要设置限制条件,这个在Xilinx ...

  7. novas的verdi和debussy是干什么用的(关于debussy的一些介绍)

    source code window: 提供了一个比较友好的界面,将整个设计的source code按设计的层次结构以树状排布,并且可以在代码上反标仿真结果,支持查找.寻找驱动等一些debug常用的操 ...

  8. LeetCode: Word Search 解题报告

    Word SearchGiven a 2D board and a word, find if the word exists in the grid. The word can be constru ...

  9. 第一章: 当前主流的小型嵌入式 GUI

    以下内容转载自安富莱电子论坛:http://forum.armfly.com/forum.php?mod=viewthread&tid=24507&highlight=%B5%B1%C ...

  10. CentOS清除用户登录记录和命令历史方法

    清除登陆系统成功的记录 [root@localhost root]# echo > /var/log/wtmp //此文件默认打开时乱码,可查到ip等信息 [root@localhost roo ...