Changeset 4960 in josm for trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
- Timestamp:
- 2012-02-16T20:58:54+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4938 r4960 85 85 } 86 86 87 public static enum SanitizeMode {88 OFF, // never sanitize the image89 ALWAYS, // always copy to a new BufferedImage90 MAKE_BUFFEREDIMAGE // make sure the returned image is instance of BufferedImage91 }92 93 87 protected Collection<String> dirs; 94 88 protected String id; … … 100 94 protected int maxWidth = -1; 101 95 protected int maxHeight = -1; 102 protected SanitizeMode sanitize;103 96 protected boolean optional; 104 97 … … 204 197 public ImageProvider setMaxHeight(int maxHeight) { 205 198 this.maxHeight = maxHeight; 206 return this;207 }208 209 /**210 * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues.211 */212 public ImageProvider setSanitize(SanitizeMode sanitize) {213 this.sanitize = sanitize;214 199 return this; 215 200 } … … 240 225 } 241 226 if (maxWidth != -1 || maxHeight != -1) 242 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight) , sanitize);227 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight)); 243 228 else 244 return ir.getImageIcon(new Dimension(width, height) , sanitize);229 return ir.getImageIcon(new Dimension(width, height)); 245 230 } 246 231 … … 292 277 if (mediatype != null && mediatype.contains("image/svg+xml")) { 293 278 URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name); 294 SVGDiagram svg = getSvgUniverse().getDiagram(uri); 295 return new ImageResource(svg); 279 return new ImageResource(getSvgUniverse().getDiagram(uri)); 296 280 } else { 297 return new ImageResource(new ImageIcon(bytes).getImage() , true);281 return new ImageResource(new ImageIcon(bytes).getImage()); 298 282 } 299 283 } … … 406 390 img = ImageIO.read(is.getFile().toURI().toURL()); 407 391 } catch (IOException e) {} 408 return img == null ? null : new ImageResource(img , true);392 return img == null ? null : new ImageResource(img); 409 393 default: 410 394 throw new AssertionError(); … … 475 459 img = ImageIO.read(new ByteArrayInputStream(buf)); 476 460 } catch (IOException e) {} 477 return img == null ? null : new ImageResource(img , false);461 return img == null ? null : new ImageResource(img); 478 462 default: 479 463 throw new AssertionError(); … … 509 493 img = ImageIO.read(path); 510 494 } catch (IOException e) {} 511 return img == null ? null : new ImageResource(img , true);495 return img == null ? null : new ImageResource(img); 512 496 default: 513 497 throw new AssertionError(); … … 767 751 } 768 752 769 public static BufferedImage sanitize(Image img) {770 (new ImageIcon(img)).getImage(); // load competely771 int width = img.getWidth(null);772 int height = img.getHeight(null);773 BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);774 result.getGraphics().drawImage(img, 0, 0, null);775 return result;776 }777 778 753 public static Image createImageFromSvg(SVGDiagram svg, Dimension dim) { 779 754 float realWidth = svg.getWidth();
Note:
See TracChangeset
for help on using the changeset viewer.
