Java Code Examples for java.awt.image.MultiResolutionImage#getResolutionVariant()
The following examples show how to use
java.awt.image.MultiResolutionImage#getResolutionVariant() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiResultionImageUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void baseMultiResImageTest() { int baseIndex = 1; int length = 4; BufferedImage[] resolutionVariants = new BufferedImage[length]; for (int i = 0; i < length; i++) { resolutionVariants[i] = createImage(i); } MultiResolutionImage bmrImage = new BaseMultiResolutionImage(baseIndex, resolutionVariants); List<Image> rvImageList = bmrImage.getResolutionVariants(); assertEquals("MultiResoltion Image shoudl contain the same number of resolution variants!", rvImageList.size(), length); for (int i = 0; i < length; i++) { int imageSize = getSize(i); Image testRVImage = bmrImage.getResolutionVariant(imageSize, imageSize); assertSame("Images should be the same", testRVImage, resolutionVariants[i]); } }
Example 2
Source File: BaseMultiResolutionImageTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static void testRVSizes() { int imageSize = getSize(1); double[][] sizeArray = { {-imageSize, imageSize}, {2 * imageSize, -2 * imageSize}, {Double.POSITIVE_INFINITY, imageSize}, {Double.POSITIVE_INFINITY, -imageSize}, {imageSize, Double.NEGATIVE_INFINITY}, {-imageSize, Double.NEGATIVE_INFINITY}, {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, {Double.NaN, imageSize}, {imageSize, Double.NaN}, {Double.NaN, Double.NaN}, {Double.POSITIVE_INFINITY, Double.NaN} }; for (double[] sizes : sizeArray) { try { MultiResolutionImage mrImage = new BaseMultiResolutionImage( 0, createRVImage(0), createRVImage(1)); mrImage.getResolutionVariant(sizes[0], sizes[1]); } catch (IllegalArgumentException ignored) { continue; } throw new RuntimeException("IllegalArgumentException is not thrown!"); } }
Example 3
Source File: BadHiDPIIcon.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static BufferedImage getBufferedImage(Image image) { if (image instanceof MultiResolutionImage) { MultiResolutionImage mrImage = (MultiResolutionImage) image; return (BufferedImage) mrImage.getResolutionVariant(32, 32); } return (BufferedImage) image; }
Example 4
Source File: BaseMultiResolutionImageTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static void testRVSizes() { int imageSize = getSize(1); double[][] sizeArray = { {-imageSize, imageSize}, {2 * imageSize, -2 * imageSize}, {Double.POSITIVE_INFINITY, imageSize}, {Double.POSITIVE_INFINITY, -imageSize}, {imageSize, Double.NEGATIVE_INFINITY}, {-imageSize, Double.NEGATIVE_INFINITY}, {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, {Double.NaN, imageSize}, {imageSize, Double.NaN}, {Double.NaN, Double.NaN}, {Double.POSITIVE_INFINITY, Double.NaN} }; for (double[] sizes : sizeArray) { try { MultiResolutionImage mrImage = new BaseMultiResolutionImage( 0, createRVImage(0), createRVImage(1)); mrImage.getResolutionVariant(sizes[0], sizes[1]); } catch (IllegalArgumentException ignored) { continue; } throw new RuntimeException("IllegalArgumentException is not thrown!"); } }
Example 5
Source File: Images.java From demo-java-x with MIT License | 5 votes |
public static void main(String[] args) throws IOException { MultiResolutionImage tokio = loadTokio(); int desiredImageWidth = ThreadLocalRandom.current().nextInt(1500); Image variant = tokio.getResolutionVariant(desiredImageWidth, 1); System.out.printf("Width of image for %d: %d%n", desiredImageWidth, variant.getWidth(null)); }
Example 6
Source File: MultiResolutionImageTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); tracker.waitForID(0); if (tracker.isErrorAny()) { throw new RuntimeException("Error during image loading"); } final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics(); setImageScalingHint(g1x, false); g1x.drawImage(image, 0, 0, null); checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); Image resolutionVariant = ((MultiResolutionImage) image). getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (resolutionVariant == null) { throw new RuntimeException("Resolution variant is null"); } MediaTracker tracker2x = new MediaTracker(new JPanel()); tracker2x.addImage(resolutionVariant, 0); tracker2x.waitForID(0); if (tracker2x.isErrorAny()) { throw new RuntimeException("Error during scalable image loading"); } final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, enableImageScaling); g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); if (!(image instanceof MultiResolutionImage)) { throw new RuntimeException("Not a MultiResolutionImage"); } MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image; Image image1x = multiResolutionImage.getResolutionVariant( IMAGE_WIDTH, IMAGE_HEIGHT); Image image2x = multiResolutionImage.getResolutionVariant( 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (image1x.getWidth(null) * 2 != image2x.getWidth(null) || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { throw new RuntimeException("Wrong resolution variant size"); } }
Example 7
Source File: MultiResolutionImageTest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); tracker.waitForID(0); if (tracker.isErrorAny()) { throw new RuntimeException("Error during image loading"); } final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics(); setImageScalingHint(g1x, false); g1x.drawImage(image, 0, 0, null); checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); Image resolutionVariant = ((MultiResolutionImage) image). getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (resolutionVariant == null) { throw new RuntimeException("Resolution variant is null"); } MediaTracker tracker2x = new MediaTracker(new JPanel()); tracker2x.addImage(resolutionVariant, 0); tracker2x.waitForID(0); if (tracker2x.isErrorAny()) { throw new RuntimeException("Error during scalable image loading"); } final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, enableImageScaling); g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); if (!(image instanceof MultiResolutionImage)) { throw new RuntimeException("Not a MultiResolutionImage"); } MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image; Image image1x = multiResolutionImage.getResolutionVariant( IMAGE_WIDTH, IMAGE_HEIGHT); Image image2x = multiResolutionImage.getResolutionVariant( 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (image1x.getWidth(null) * 2 != image2x.getWidth(null) || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { throw new RuntimeException("Wrong resolution variant size"); } }