MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / scaleImageIcon

Method scaleImageIcon

ij/src/main/java/ij/gui/GUI.java:582–610  ·  view source on GitHub ↗
(ImageIcon in, double factor)

Source from the content-addressed store, hash-verified

580 }
581
582 @AstroImageJ(reason = "Scale frames")
583 private static ImageIcon scaleImageIcon(ImageIcon in, double factor) {
584 if (in == null || factor <= 0) {
585 return in;
586 }
587
588 var img = in.getImage();
589 if (img == null) {
590 return in;
591 }
592
593 var w = img.getWidth(null);
594 var h = img.getHeight(null);
595 if (w <= 0 || h <= 0) {
596 return in;
597 }
598
599 var nw = Math.max(1, (int) Math.round(w * factor));
600 var nh = Math.max(1, (int) Math.round(h * factor));
601
602 var bufferedImage = new BufferedImage(nw, nh, BufferedImage.TYPE_INT_ARGB);
603 var g2 = bufferedImage.createGraphics();
604 g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
605 g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
606 g2.drawImage(img, 0, 0, nw, nh, null);
607 g2.dispose();
608
609 return new ImageIcon(bufferedImage, in.getDescription());
610 }
611
612 /** Works around an OpenJDK bug on Windows that
613 * causes the scrollbar thumb color and background

Callers 1

scaleMethod · 0.95

Calls 8

setRenderingHintMethod · 0.80
getDescriptionMethod · 0.80
getImageMethod · 0.65
getWidthMethod · 0.45
getHeightMethod · 0.45
maxMethod · 0.45
roundMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected