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. FreeSWITCH检测DTMF数据的方法

    一.RFC2833 1. 介绍: RFC2833为带内检测方式,通过RTP传输,由特殊的rtpPayloadType即TeleponeEvent来标示RFC2833数据包.同一个DTMF按键通常会对应 ...

  2. mysql 更新数据表的记录

    对于表里的记录值,可以通过update 命令进行更改,语法如下: UPDATE tablename SET field1=value1,field2.=value2,……fieldn=valuen [ ...

  3. 怎么使用 bat 使用日期时间重命名文件名

    d: rename A.txt "A%date:~0,4%-%date:~5,2%-%date:~8,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%_backu ...

  4. [Jobdu] 题目1500:出操队形

    题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往楼下跑了,然后身高矮的排在队伍的前面,身高较高的就要排在队尾.突然,有一天出操负责人想了一个 ...

  5. CentOS 6.9升级GCC至7.3.0版本

    1.查看当前centos版本:  cat /etc/redhat-release 2. 安装centos6.9默认的开发工具,包含gcc,g++,make等等一系列工具: yum groupinsta ...

  6. 【Android】3.18 示例18--自定义绘制功能

    分类:C#.Android.VS2015.百度地图应用: 创建日期:2016-02-04 简介:介绍自定义绘制点.线.多边形.圆等几何图形和文字 详述: (1)支持绘制凸多边形,如要绘制凹多边形请用三 ...

  7. XMLHttpRequest使用详解

    1.什么是XMLHttpRequest XMLHttpRequest是一个浏览器接口,使得Javascript可以进行HTTP(S)通信,这就是我们熟悉的AJAX.早期,各个浏览器的实现都不同,HTM ...

  8. 双系统中ubuntu的安装方法

    双系统中ubuntu的安装方法 注意:给电脑安装双系统时,一定要先装Windows系统,再安装Linux系统! 原因是电脑开机后,要先执行一段bootloader引导程序:再由引导程序启动操作系统.W ...

  9. VC++ 知识点

    1.寻找文件时,CFileFind类的使用. 2.寻找目录时使用BROWSEINFO,其中包含了用户选中目录的重要信息. 3.LPITEMIDLIST类 4.目录选择对话框的使用SHBrowseFor ...

  10. 影梭Android版使用教程

    影梭Android版使用教程  2015年5月13日  admin  影梭使用教程 下载影梭Android版客户端 安卓客户端下载:下载地址 安装并打开影梭 按下图说明设置服务器.远程端口.密码和加密 ...