public static void drawDipImage(Graphics g, Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, @Nullable ImageObserver observer) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D)g.create(0, 0, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage)image).getDelegate(); if (img == null) { img = image; } newG.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); newG.scale(1, 1); newG.dispose(); } else { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } }
public static void drawDipImage(Graphics g, Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, @Nullable ImageObserver observer) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D) g.create(0, 0, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage) image).getDelegate(); if (img == null) { img = image; } newG.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); newG.scale(1, 1); newG.dispose(); } else { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } }
public static void drawImage(Graphics g, Image image, int x, int y, int width, int height, ImageObserver observer) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D) g.create(x, y, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage) image).getDelegate(); if (img == null) { img = image; } if (width == -1 && height == -1) { newG.drawImage(img, 0, 0, observer); } else { newG.drawImage(img, 0, 0, width * 2, height * 2, 0, 0, width * 2, height * 2, observer); } //newG.scale(1, 1); newG.dispose(); } else if (width == -1 && height == -1) { g.drawImage(image, x, y, observer); } else { g.drawImage(image, x, y, x + width, y + height, 0, 0, width, height, observer); } }
public static BufferedImage toBufferedImage(@Nonnull Image image) { if (image instanceof JBHiDPIScaledImage) { Image img = ((JBHiDPIScaledImage)image).getDelegate(); if (img != null) { image = img; } } if (image instanceof BufferedImage) { return (BufferedImage)image; } @SuppressWarnings("UndesirableClassUsage") BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bufferedImage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return bufferedImage; }
public static boolean isRetinaImage(@Nullable BufferedImage image) { if (image == null) { return false; } return image instanceof JBHiDPIScaledImage || SystemInfo.isAppleJvm && UIUtil.isAppleRetina() && BufferedImage.class != image.getClass(); }
public static void drawImage(Graphics g, Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D)g.create(0, 0, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage)image).getDelegate(); if (img == null) { img = image; } newG.drawImage(img, 2 * dx1, 2 * dy1, 2 * dx2, 2 * dy2, sx1 * 2, sy1 * 2, sx2 * 2, sy2 * 2, observer); newG.scale(1, 1); newG.dispose(); } else if (RetinaImage.isAppleHiDPIScaledImage(image)) { g.drawImage(image, dx1, dy1, dx2, dy2, sx1 * 2, sy1 * 2, sx2 * 2, sy2 * 2, observer); } else { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } }
public static void drawImage(Graphics g, Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { if(image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D) g.create(0, 0, image.getWidth(observer), image.getHeight(observer)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage) image).getDelegate(); if(img == null) { img = image; } newG.drawImage(img, 2 * dx1, 2 * dy1, 2 * dx2, 2 * dy2, sx1 * 2, sy1 * 2, sx2 * 2, sy2 * 2, observer); newG.scale(1, 1); newG.dispose(); } else if(RetinaImage.isAppleHiDPIScaledImage(image)) { g.drawImage(image, dx1, dy1, dx2, dy2, sx1 * 2, sy1 * 2, sx2 * 2, sy2 * 2, observer); } else { g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } }
public static void drawImage(Graphics g, BufferedImage image, BufferedImageOp op, int x, int y) { if (image instanceof JBHiDPIScaledImage) { final Graphics2D newG = (Graphics2D) g.create(x, y, image.getWidth(null), image.getHeight(null)); newG.scale(0.5, 0.5); Image img = ((JBHiDPIScaledImage) image).getDelegate(); if (img == null) { img = image; } newG.drawImage((BufferedImage) img, op, 0, 0); //newG.scale(1, 1); newG.dispose(); } else { ((Graphics2D) g).drawImage(image, op, x, y); } }
public static int getRealWidth(@Nonnull Image image) { if (image instanceof JBHiDPIScaledImage) { Image img = ((JBHiDPIScaledImage)image).getDelegate(); if (img != null) image = img; } return image.getWidth(null); }
public static int getRealHeight(@Nonnull Image image) { if (image instanceof JBHiDPIScaledImage) { Image img = ((JBHiDPIScaledImage)image).getDelegate(); if (img != null) image = img; } return image.getHeight(null); }
public static int getUserWidth(@Nonnull Image image) { if (image instanceof JBHiDPIScaledImage) { return ((JBHiDPIScaledImage)image).getUserWidth(null); } return image.getWidth(null); }
public static int getUserHeight(@Nonnull Image image) { if (image instanceof JBHiDPIScaledImage) { return ((JBHiDPIScaledImage)image).getUserHeight(null); } return image.getHeight(null); }