Changeset 4961 in josm
- Timestamp:
- 2012-02-16T21:21:17+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4960 r4961 279 279 return new ImageResource(getSvgUniverse().getDiagram(uri)); 280 280 } else { 281 return new ImageResource(new ImageIcon(bytes).getImage()); 281 try { 282 return new ImageResource(ImageIO.read(new ByteArrayInputStream(bytes))); 283 } catch (IOException e) {} 282 284 } 283 285 } … … 751 753 } 752 754 753 public static Image createImageFromSvg(SVGDiagram svg, Dimension dim) {755 public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) { 754 756 float realWidth = svg.getWidth(); 755 757 float realHeight = svg.getHeight(); … … 772 774 width = (int) Math.round(realWidth * scaleX); 773 775 } 774 Image img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);775 Graphics2D g = ((BufferedImage) img).createGraphics();776 BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 777 Graphics2D g = img.createGraphics(); 776 778 g.setClip(0, 0, width, height); 777 779 if (scaleX != null) { -
trunk/src/org/openstreetmap/josm/tools/ImageResource.java
r4960 r4961 22 22 * Caches the image data for resized versions of the same image. 23 23 */ 24 private HashMap<Dimension, Image> imgCache = new HashMap<Dimension,Image>();24 private HashMap<Dimension, BufferedImage> imgCache = new HashMap<Dimension, BufferedImage>(); 25 25 private SVGDiagram svg; 26 26 public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1); 27 27 28 public ImageResource( Image img) {28 public ImageResource(BufferedImage img) { 29 29 CheckParameterUtil.ensureParameterNotNull(img); 30 30 imgCache.put(DEFAULT_DIMENSION, img); … … 49 49 if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0) 50 50 throw new IllegalArgumentException(); 51 Image img = imgCache.get(dim);51 BufferedImage img = imgCache.get(dim); 52 52 if (img != null) { 53 53 return new ImageIcon(img); … … 58 58 return new ImageIcon(img); 59 59 } else { 60 Image base = imgCache.get(DEFAULT_DIMENSION);60 BufferedImage base = imgCache.get(DEFAULT_DIMENSION); 61 61 if (base == null) throw new AssertionError(); 62 62 … … 69 69 height = icon.getIconHeight() * width / icon.getIconWidth(); 70 70 } 71 img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); 71 Image i = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); 72 img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 73 img.getGraphics().drawImage(i, 0, 0, null); 72 74 imgCache.put(dim, img); 73 75 return new ImageIcon(img); … … 91 93 realHeight = svg.getHeight(); 92 94 } else { 93 Image base = imgCache.get(DEFAULT_DIMENSION);95 BufferedImage base = imgCache.get(DEFAULT_DIMENSION); 94 96 if (base == null) throw new AssertionError(); 95 97 ImageIcon icon = new ImageIcon(base);
Note:
See TracChangeset
for help on using the changeset viewer.