Changeset 12723 in josm
- Timestamp:
- 2017-09-04T19:22:41+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r12722 r12723 59 59 public ImageResource(Image img) { 60 60 CheckParameterUtil.ensureParameterNotNull(img); 61 baseImage = scaleBaseImageIfNeeded(img); 62 } 63 64 /** Scale image according to screen DPI if needed. 65 * 66 * @param img an image loaded from file (it's width and height are virtual pixels) 67 * @return original img if virtual size is the same as real size or new image resized to real pixels 68 */ 69 private static Image scaleBaseImageIfNeeded(Image img) { 70 int imgWidth = img.getWidth(null); 71 int imgHeight = img.getHeight(null); 72 int realWidth = GuiSizesHelper.getSizeDpiAdjusted(imgWidth); 73 int realHeight = GuiSizesHelper.getSizeDpiAdjusted(imgHeight); 74 if (realWidth != -1 && realHeight != -1 && imgWidth != realWidth && imgHeight != realHeight) { 75 Image realImage = img.getScaledInstance(realWidth, realHeight, Image.SCALE_SMOOTH); 76 BufferedImage bimg = new BufferedImage(realWidth, realHeight, BufferedImage.TYPE_INT_ARGB); 77 bimg.getGraphics().drawImage(realImage, 0, 0, null); 78 return bimg; 79 } 80 return img; 61 baseImage = img; 81 62 } 82 63 … … 162 143 return getImageIcon(dim, true); 163 144 } 164 145 165 146 /** 166 147 * Get an ImageIcon object for the image of this resource. … … 229 210 } catch (NoClassDefFoundError e) { 230 211 return new ImageIcon(img); 231 } 212 } 232 213 } 233 214 }
Note:
See TracChangeset
for help on using the changeset viewer.