@Nullable public static BufferedImage convertToRetina(@NotNull BufferedImage image) { final int scale = 2; if (image.getWidth() < scale || image.getHeight() < scale) { // Can't convert to Retina; see issue 65676 return null; } try { @SuppressWarnings("ConstantConditions") Image retina = RetinaImage.createFrom(image, scale, null); if (!(retina instanceof BufferedImage)) { // Don't try this again ourRetinaCapable = false; return null; } return (BufferedImage)retina; } catch (Throwable t) { // Can't always create Retina images (see issue 65609); fall through to non-Retina code path ourRetinaCapable = false; return null; } }
@Nullable public static BufferedImage convertToRetina(@NotNull BufferedImage image) { final int scale = 2; if (image.getWidth() < scale || image.getHeight() < scale) { // Can't convert to Retina; see issue 65676 return null; } try { @SuppressWarnings("ConstantConditions") Image retina = RetinaImage.createFrom(image, scale, null); if (!(retina instanceof BufferedImage)) { // Don't try this again ourRetinaCapable = false; return null; } return (BufferedImage) retina; } catch (Throwable t) { // Can't always create Retina images (see issue 65609); fall through to non-Retina code path ourRetinaCapable = false; return null; } }
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); } }
/** * Gets (creates if necessary) disabled icon based on the passed one. * * @return <code>ImageIcon</code> constructed from disabled image of passed icon. */ @Nullable public static Icon getDisabledIcon(Icon icon) { if (icon instanceof LazyIcon) icon = ((LazyIcon)icon).getOrComputeIcon(); if (icon == null) return null; Icon disabledIcon = ourIcon2DisabledIcon.get(icon); if (disabledIcon == null) { if (!isGoodSize(icon)) { LOG.error(icon); // # 22481 return EMPTY_ICON; } final int scale = UIUtil.isRetina() ? 2 : 1; @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage(scale*icon.getIconWidth(), scale*icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics = image.createGraphics(); graphics.setColor(UIUtil.TRANSPARENT_COLOR); graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); graphics.scale(scale, scale); icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0); graphics.dispose(); Image img = createDisabled(image); if (UIUtil.isRetina()) img = RetinaImage.createFrom(img, 2, ImageLoader.ourComponent); disabledIcon = new MyImageIcon(img); ourIcon2DisabledIcon.put(icon, disabledIcon); } return disabledIcon; }
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); } }
@NotNull public static BufferedImage createImage(int width, int height, int type) { if (isRetina()) { return RetinaImage.create(width, height, type); } //noinspection UndesirableClassUsage return new BufferedImage(width, height, type); }
@NotNull public static BufferedImage createImageForGraphics(Graphics2D g, int width, int height, int type) { if (isRetina(g)) { return RetinaImage.create(width, height, type); } //noinspection UndesirableClassUsage return new BufferedImage(width, height, type); }