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 ...
随机推荐
- 从错误中学python(4)——最小公约数与辗转相除法
题目 给你两个正整数a和b, 输出它们的最大公约数 辗转相除法 辗转相除法的步骤 def gcd(b,a): b,a=a,b%a if a==0: return b else: return gcd( ...
- oracle关键字大全--注意不要乱用哦
遇到怀疑可能使用了关键字,就来搜一搜吧 ... Oracle 关键字(保留字) 大全 其实这个东西可以在oracle 上输入一个sql语句就可以得到: select * from v$reserved ...
- linux修改yum本地源的方法
CentOS 系统下修改yum本地源: mkdir /mnt/cdrom/ cd /etc/yum.repos.d/mv CentOS-Base.repo CentOS-Base.repo.bakvi ...
- IOS5 ARC unsafe_unretained等说明
转自:http://blog.csdn.net/bsplover/article/details/7707964 iOS5中加入了新知识,就是ARC,其实我并不是很喜欢它,因为习惯了自己管理内存.但是 ...
- css 样式使用方法的累积
我们直接看样例然后在来解释使用方法. <!DOCTYPE html> <html> <head> <style> input[type="ch ...
- Linux音频编程指南(转)
转自: http://www.ibm.com/developerworks/cn/linux/l-audio/ Linux音频编程指南 虽然目前Linux的优势主要体现在网络服务方面,但事实上同样也有 ...
- vue实现前端导出excel表格
1.在src目录下创建一个文件(vendor)进入Blob.js和Export2Excel.js 2.npm install -S file-saver 用来生成文件的web应用程序 3.npm in ...
- 利用对象思想来绘制canvas帧动画
绘制思路: 1.封装一个对象出来: 2.属性: width . height imgSr speed dir3.行为: render changeDir html文件: <script> ...
- JSP/Servlet中文乱码处理总结
下面的任何一条缺一不可,注意,我之所以全部都用的XXX,意思就是这几个最好全部都一致! 1.HTML中要用meta content="text/html; charset=XXX" ...
- Eclipse中Editor开启Auto-completion
Java Editor .abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Java Script Editor 现在Eclipse限制使用最多 ...