<AWT Dev> [9] Review request for 8029339 Custom MultiResolution image support on HiDPI displays
Alexander Scherbatiy
alexandr.scherbatiy at oracle.com
Tue Jan 14 02:54:28 PST 2014
Hello,
Could you review the fix:
bug: https://bugs.openjdk.java.net/browse/JDK-8029339
webrev: http://cr.openjdk.java.net/~alexsch/8029339/webrev.00
This is a proposal to introduce an API that allows to create a custom
multi resolution image.
I. It seems reasonable that the API should provide two basic operations:
1. Get the resolution variant based on the requested image width and
height:
- Image getResolutionVariant(int width, int height)
Usually the system provides the scale factor which represents the
number of pixels corresponding to each linear unit on the display.
However, it has sense to combine the scale factor and the current
transformations to get the actual image size to be displayed.
2. Get all provided resolution variants:
- List<Image> getResolutionVariants()
There are several uses cases:
- Create a new multi-resolution image based on the given
multi-resolution image.
- Pass to the native system the multi-resolution image. For example,
a use can set to the system the custom multi-resolution cursor.
II. There are some possible ways where the new API can be added
1. java.awt.Image.
The 2 new methods can be added to the Image class. A user can override
the getResolutionVariant() and getResolutionVariants() methods to
provide the resolution variants
or there can be default implementations of these methods if a user
puts resolution variants
to the list in the sorted order.
To check that the image has resolution variants the following
statement can be used: image.getResolutionVariants().size() != 1
The disadvantage is that there is an overhead that the Image class
should contain the List object and not all
images can have resolution variants.
2. Introduce new MultiResolutionImage interface.
A user should extend Image class and implement the
MultiResolutionImage interface.
For example:
---------------------
public class CustomMultiResolutionImage extends BufferedImage
implements MultiResolutionImage {
Image highResolutionImage;
public CustomMultiResolutionImage(BufferedImage baseImage,
BufferedImage highResolutionImage) {
super(baseImage.getWidth(), baseImage.getHeight(),
baseImage.getType());
this.highResolutionImage = highResolutionImage;
Graphics g = getGraphics();
g.drawImage(baseImage, 0, 0, null);
g.dispose();
}
@Override
public Image getResolutionVariant(int width, int height) {
return ((width <= getWidth() && height <= getHeight()))
? this : highResolutionImage;
}
@Override
public List<Image> getResolutionVariants() {
return Arrays.asList(this, highResolutionImage);
}
}
---------------------
The current fix adds the MultiResolutionImage interface and public
resolution variant rendering hints.
Thanks,
Alexandr.
More information about the awt-dev
mailing list