跳到主要内容

JEP 251:多分辨率图像

QWen Max 中英对照

概述

定义一个多分辨率图像 API,以便可以轻松操作和显示具有分辨率变体的图像。

描述

这个新 API 将在 java.awt.image 包中定义,允许将一组不同分辨率的图像封装到一个多重分辨率图像中。

多分辨率图像的基本操作包括:

  • 根据给定的 DPI 指标和图像变换集合,检索分辨率特定的图像变体,以及

  • 检索图像中的所有变体。

除了这些操作之外,多分辨率图像在其他方面的行为与普通图像相同。java.awt.Graphics 类会根据当前显示的 DPI 指标和任何应用的变换,从多分辨率图像中检索所需的变体。

提议的 API 草图:

package java.awt.image;

/**
* This interface is designed to provide a set of images at various resolutions.
*
* The {@code MultiResolutionImage} interface should be implemented by any
* class whose instances are intended to provide image resolution variants
* according to the given image width and height.
*
* @since 1.9
*/
public interface MultiResolutionImage {

/**
* Gets a specific image that is the best variant to represent
* this logical image at the indicated size.
*
* @param destImageWidth the width of the destination image, in pixels.
* @param destImageHeight the height of the destination image, in pixels.
* @return image resolution variant.
*
* @since 1.9
*/
Image getResolutionVariant(float destImageWidth, float destImageHeight);

/**
* Gets a readable list of all resolution variants.
* Note that many implementations might return an unmodifiable list.
*
* @return list of resolution variants.
* @since 1.9
*/
public List<Image> getResolutionVariants();
}

替代方案

在当前的 Java 2D API 中,无法检测是否正在使用高分辨率显示器。至少必须提供 DPI 缩放比例。开发人员可以使用缩放比例绘制具有必要分辨率的图像,但这可能会非常繁琐。

测试

新的 API 需要在搭载 Retina 显示屏的 Mac OS X 和搭载 HiDPI 显示屏的 Windows 上进行测试。

可以测试以下场景:

  • 从一组图像创建多分辨率图像,

  • 从遵循常规缩放命名约定的文件系统中的图像创建多分辨率图像,

  • 基于另一个多分辨率图像创建多分辨率图像,以及

  • 使用不同的 DPI 指标和应用的变换绘制多分辨率图像。