Changeset 4961 in josm for trunk/src


Ignore:
Timestamp:
2012-02-16T21:21:17+01:00 (8 years ago)
Author:
stoecker
Message:

see #1576 - switch ImageResource complete to BufferedImage, fix last accidential checkin

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r4960 r4961  
    279279                        return new ImageResource(getSvgUniverse().getDiagram(uri));
    280280                    } else {
    281                         return new ImageResource(new ImageIcon(bytes).getImage());
     281                        try {
     282                            return new ImageResource(ImageIO.read(new ByteArrayInputStream(bytes)));
     283                        } catch (IOException e) {}
    282284                    }
    283285                }
     
    751753    }
    752754
    753     public static Image createImageFromSvg(SVGDiagram svg, Dimension dim) {
     755    public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) {
    754756        float realWidth = svg.getWidth();
    755757        float realHeight = svg.getHeight();
     
    772774            width = (int) Math.round(realWidth * scaleX);
    773775        }
    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();
    776778        g.setClip(0, 0, width, height);
    777779        if (scaleX != null) {
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r4960 r4961  
    2222     * Caches the image data for resized versions of the same image.
    2323     */
    24     private HashMap<Dimension, Image> imgCache = new HashMap<Dimension, Image>();
     24    private HashMap<Dimension, BufferedImage> imgCache = new HashMap<Dimension, BufferedImage>();
    2525    private SVGDiagram svg;
    2626    public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1);
    2727 
    28     public ImageResource(Image img) {
     28    public ImageResource(BufferedImage img) {
    2929        CheckParameterUtil.ensureParameterNotNull(img);
    3030        imgCache.put(DEFAULT_DIMENSION, img);
     
    4949        if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0)
    5050            throw new IllegalArgumentException();
    51         Image img = imgCache.get(dim);
     51        BufferedImage img = imgCache.get(dim);
    5252        if (img != null) {
    5353            return new ImageIcon(img);
     
    5858            return new ImageIcon(img);
    5959        } else {
    60             Image base = imgCache.get(DEFAULT_DIMENSION);
     60            BufferedImage base = imgCache.get(DEFAULT_DIMENSION);
    6161            if (base == null) throw new AssertionError();
    6262           
     
    6969                height = icon.getIconHeight() * width / icon.getIconWidth();
    7070            }
    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);
    7274            imgCache.put(dim, img);
    7375            return new ImageIcon(img);
     
    9193            realHeight = svg.getHeight();
    9294        } else {
    93             Image base = imgCache.get(DEFAULT_DIMENSION);
     95            BufferedImage base = imgCache.get(DEFAULT_DIMENSION);
    9496            if (base == null) throw new AssertionError();
    9597            ImageIcon icon = new ImageIcon(base);
Note: See TracChangeset for help on using the changeset viewer.