The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
As you have already learned from the Images lesson, 正如您已经从图像课程中了解到的,Image
s are described by a width and a height, measured in pixels, and have a coordinate system that is independent of the drawing surface.Image
以宽度和高度(以像素为单位)进行描述,并且具有独立于图形表面的坐标系。
There are a number of common tasks when working with images.处理图像时有许多常见任务。
This lesson teaches you the basics of loading, displaying, and saving images.本课程将向您介绍加载、显示和保存图像的基本知识。
The are two main classes that you must learn about to work with images:要使用图像,您必须学习以下两个主要类:
java.awt.Image
class is the superclass that represents graphical images as rectangular arrays of pixels.java.awt.Image
类是将图形图像表示为像素矩形数组的超类。java.awt.image.BufferedImage
class, which extends the Image
class to allow the application to operate directly with image data (for example, retrieving or setting up the pixel color). java.awt.image.BufferedImage
类,它扩展了Image
类,允许应用程序直接使用图像数据进行操作(例如,检索或设置像素颜色)。The BufferedImage
class is a cornerstone of the Java 2D immediate-mode imaging API. BuffereImage
类是Java2D即时模式成像API的基石。It manages the image in memory and provides methods for storing, interpreting, and obtaining pixel data. 它管理内存中的图像,并提供存储、解释和获取像素数据的方法。Since 由于BufferedImage
is a subclass of Image
it can be rendered by the Graphics
and Graphics2D
methods that accept an Image
parameter.BuffereImage
是Image
的一个子类,因此可以通过接受Image
参数的Graphics
和Graphics2D
方法进行渲染。
A BufferedImage
is essentially an Image
with an accessible data buffer. BuffereImage
本质上是具有可访问数据缓冲区的Image
。It is therefore more efficient to work directly with 因此,直接使用BufferedImage
. BuffereImage
更有效。A BufferedImage
has a ColorModel and a Raster of image data. BuffereImage
具有ColorModel
和图像数据光栅。The ColorModel provides a color interpretation of the image's pixel data.ColorModel
提供图像像素数据的颜色解释。
The Raster performs the following functions:光栅执行以下功能:
The basic operations with images are represented in the following sections:以下部分介绍了图像的基本操作:
This section explains how to load an image from an external image format into a Java application using the Image I/O API本节介绍如何使用图像I/O API将图像从外部图像格式加载到Java应用程序中
This section teaches how to display images using the 本节介绍如何使用drawImage
method of the Graphics
and Graphics2D
classes.Graphics
和Graphics2D
类的drawImage
方法显示图像。
This section describes how to create an image and how to use the image itself as a drawing surface.本节介绍如何创建图像以及如何将图像本身用作绘图曲面。
This section explains how to save created images in an appropriate format.本节介绍如何以适当的格式保存创建的图像。